Fix access out of bounds in the text's multi-language support. 19/128619/1
authorVictor Cebollada <v.cebollada@samsung.com>
Wed, 10 May 2017 13:39:51 +0000 (14:39 +0100)
committerVictor Cebollada <v.cebollada@samsung.com>
Wed, 10 May 2017 13:51:04 +0000 (14:51 +0100)
*  If the script is unknown it will access a vector out of bounds.

Change-Id: Ia1f670f1f50296ec4a8d7b88401574e074147d40
Signed-off-by: Victor Cebollada <v.cebollada@samsung.com>
automated-tests/src/dali-toolkit-internal/utc-Dali-Text-MultiLanguage.cpp
dali-toolkit/internal/text/multi-language-support-impl.cpp

index 3904faa..c3f0b9b 100644 (file)
@@ -1614,6 +1614,38 @@ int UtcDaliTextMultiLanguageValidateFonts01(void)
   fontDescriptions10.PushBack( fontDescription1003 );
   fontDescriptions10.PushBack( fontDescription1004 );
 
+  FontRun fontRun1101 =
+  {
+    {
+      0u,
+      22u
+    },
+    5u
+  };
+  Vector<FontRun> fontRuns11;
+  fontRuns11.PushBack( fontRun1101 );
+
+  FontDescriptionRun fontDescription1101 =
+  {
+    {
+      0,
+      22u
+    },
+    const_cast<char*>( "TizenSans" ),
+    9u,
+    TextAbstraction::FontWeight::NORMAL,
+    TextAbstraction::FontWidth::NORMAL,
+    TextAbstraction::FontSlant::NORMAL,
+    pointSize02,
+    true,
+    false,
+    false,
+    false,
+    true
+  };
+  Vector<FontDescriptionRun> fontDescriptions11;
+  fontDescriptions11.PushBack( fontDescription1101 );
+
   const ValidateFontsData data[] =
   {
     {
@@ -1716,8 +1748,18 @@ int UtcDaliTextMultiLanguageValidateFonts01(void)
       fontDescriptions10,
       fontRuns10
     },
+    {
+      "Unknown script -> changed to LATIN",
+      "WRC – The Official App",
+      "/tizen/TizenSansRegular.ttf",
+      TextAbstraction::FontClient::DEFAULT_POINT_SIZE,
+      0u,
+      22u,
+      fontDescriptions11,
+      fontRuns11
+    },
   };
-  const unsigned int numberOfTests = 10u;
+  const unsigned int numberOfTests = 11u;
 
   for( unsigned int index = 0u; index < numberOfTests; ++index )
   {
index 260bd5a..fd1d8e4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -477,9 +477,9 @@ void MultilanguageSupport::ValidateFonts( const Vector<Character>& text,
     currentFontId = fontId;
 
     // Get the script for the current character.
-    const Script script = GetScript( index,
-                                     scriptRunIt,
-                                     scriptRunEndIt );
+    Script script = GetScript( index,
+                               scriptRunIt,
+                               scriptRunEndIt );
 
 #ifdef DEBUG_ENABLED
     {
@@ -494,6 +494,10 @@ void MultilanguageSupport::ValidateFonts( const Vector<Character>& text,
                      description.path.c_str() );
     }
 #endif
+    if (script == TextAbstraction::UNKNOWN)
+    {
+      script = TextAbstraction::LATIN;
+    }
 
     // Validate whether the current character is supported by the given font.
     bool isValidFont = false;