If the text size is too large, crash or deadlock will occur. 67/205267/14
authorJoogab Yun <joogab.yun@samsung.com>
Thu, 2 May 2019 01:30:44 +0000 (10:30 +0900)
committerJoogab Yun <joogab.yun@samsung.com>
Thu, 23 May 2019 00:38:11 +0000 (09:38 +0900)
So, we limit the length.

  3  Dali::Toolkit::Text::ShapeText (text=..., lineBreakInfo=..., scripts=..., fonts=..., startCharacterIndex=startCharacterIndex@entry=0,
        startGlyphIndex=0, numberOfCharacters=numberOfCharacters@entry=51371,
        glyphs=..., glyphToCharacterMap=..., charactersPerGlyph=...,
        newParagraphGlyphs=...) at
        /usr/src/debug/dali-toolkit-1.3.50.1/build/tizen/dali-toolkit/../../../dali-toolkit/internal/text/shaper.cpp:200
        ...
                currentIndex = 40291
                numberOfGlyphsReserved = 66782
                totalNumberOfGlyphs = 40203
                numberOfNewGlyphs = 40203
                glyphToCharacterMapBuffer = 0x9f85f8
                glyphIndex = 40196
                lastCharacter = 51371
                lastGlyph = <optimized out>

        (gdb)bt
        0  memmove () at /usr/src/debug//////////////glibc-2.24/string/../sysdeps/arm/memmove.S:124
        1  0xaaa57450 in Dali::VectorAlgorithms<true>::Insert (this=0x9c67f8, at=0x896204a0 "", from=0x9f85f8 "\022", to=<optimized out>,
        elementSize=36) at /usr/include/dali/public-api/common/dali-vector.h:373
        2  0xaaa7d25e in Dali::Vector<Dali::TextAbstraction::GlyphInfo, true>::Insert (to=<optimized out>, from=0x9f85f8, at=0x896204a0,
        this=0x9c67f8) at /usr/include/dali/public-api/common/dali-vector.h:624
        3  Dali::Toolkit::Text::ShapeText (text=..., lineBreakInfo=..., scripts=..., fonts=..., startCharacterIndex=startCharacterIndex@entry=0, startGlyphIndex=0,
        numberOfCharacters=numberOfCharacters@entry=51371, glyphs=..., glyphToCharacterMap=..., charactersPerGlyph=...,
        newParagraphGlyphs=...) at /usr/src/debug/dali-toolkit-1.3.50.1/build/tizen/dali-toolkit/../../../dali-toolkit/internal/text/shaper.cpp:200
        4  0xaaa85b68 in Dali::Toolkit::Text::Controller::Impl::UpdateModel (this=0x9f9760, operationsRequired=<optimized out>) at
        /usr/src/debug/dali-toolkit-1.3.50.1/build/tizen/dali-toolkit/../../../dali-toolkit/internal/text/text-controller-impl.cpp:1019

Change-Id: Ic903833a638afaeb8749dfd1f44cd1d40f5f6939

automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Controller.cpp
dali-toolkit/internal/text/text-controller.cpp

index 95f7697..e581626 100755 (executable)
@@ -1045,3 +1045,41 @@ int UtcDaliTextControllerSelectEvent(void)
 
   END_TEST;
 }
+
+
+int UtcDaliTextControllerMaxLengthSetText(void)
+{
+  tet_infoline(" UtcDaliTextControllerMaxLengthSetText");
+  ToolkitTestApplication application;
+
+  // Creates a text controller.
+  ControllerPtr controller = Controller::New();
+
+  ConfigureTextLabel(controller);
+
+  const Length MAX_TEXT_LENGTH = 1024u * 32u;
+
+  // make over length world
+  int maxLength = (1024u * 32u) + 10u;
+  char world[maxLength];
+  for( int i = 0; i < maxLength; i++ )
+  {
+    world[i] = 'a';
+  }
+
+  // Set the text
+  std::string text(world);
+  controller->SetText( text );
+
+  // Perform a relayout
+  const Size size( Dali::Stage::GetCurrent().GetSize() );
+  controller->Relayout(size);
+
+  // check text length
+  controller->GetText( text );
+  Length textSize = text.size();
+
+  DALI_TEST_EQUALS( MAX_TEXT_LENGTH, textSize, TEST_LOCATION );
+
+  END_TEST;
+}
index e0c63c8..36314c9 100755 (executable)
@@ -61,6 +61,7 @@ const char * const PLACEHOLDER_FONT_STYLE = "fontStyle";
 const char * const PLACEHOLDER_POINT_SIZE = "pointSize";
 const char * const PLACEHOLDER_PIXEL_SIZE = "pixelSize";
 const char * const PLACEHOLDER_ELLIPSIS = "ellipsis";
+const unsigned int MAX_TEXT_LENGTH = 1024u * 32u;
 
 float ConvertToEven( float value )
 {
@@ -309,7 +310,7 @@ bool Controller::IsSmoothHandlePanEnabled() const
 
 void Controller::SetMaximumNumberOfCharacters( Length maxCharacters )
 {
-  mImpl->mMaximumNumberOfCharacters = maxCharacters;
+  mImpl->mMaximumNumberOfCharacters = std::min( maxCharacters, MAX_TEXT_LENGTH );
 }
 
 int Controller::GetMaximumNumberOfCharacters()
@@ -592,6 +593,13 @@ void Controller::SetText( const std::string& text )
       utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
     }
 
+    // Limit the text size. If the text size is too large, crash or deadlock will occur.
+    if( textSize > MAX_TEXT_LENGTH )
+    {
+      DALI_LOG_WARNING( "The text size is too large(%d), limit the length to 32,768u\n", textSize );
+      textSize = MAX_TEXT_LENGTH;
+    }
+
     //  Convert text into UTF-32
     Vector<Character>& utf32Characters = mImpl->mModel->mLogicalModel->mText;
     utf32Characters.Resize( textSize );