OSDN Git Service

Add bound checks to utf16_to_utf8
authorSergio Giro <sgiro@google.com>
Tue, 28 Jun 2016 17:26:10 +0000 (18:26 +0100)
committerMartijn Coenen <maco@google.com>
Thu, 25 Aug 2016 10:19:12 +0000 (12:19 +0200)
Test: ran libaapt2_tests64
Bug: 29250543
Change-Id: I1ebc017af623b6514cf0c493e8cd8e1d59ea26c3
(cherry picked from commit 4781057e78f63e0e99af109cebf3b6a78f4bfbb6)

tools/aapt/Android.mk
tools/aapt2/util/Util.cpp
tools/split-select/Android.mk

index b701445..2a490d1 100644 (file)
@@ -57,8 +57,8 @@ aaptTests := \
 aaptHostStaticLibs := \
     libandroidfw \
     libpng \
-    liblog \
     libutils \
+    liblog \
     libcutils \
     libexpat \
     libziparchive-host \
index 7ee6e77..e07c88e 100644 (file)
@@ -445,8 +445,10 @@ std::string utf16ToUtf8(const StringPiece16& utf16) {
     }
 
     std::string utf8;
+    // Make room for '\0' explicitly.
+    utf8.resize(utf8Length + 1);
+    utf16_to_utf8(utf16.data(), utf16.length(), &*utf8.begin(), utf8Length + 1);
     utf8.resize(utf8Length);
-    utf16_to_utf8(utf16.data(), utf16.length(), &*utf8.begin());
     return utf8;
 }
 
index 239bed5..863abae 100644 (file)
@@ -47,8 +47,8 @@ hostStaticLibs := \
     libaapt \
     libandroidfw \
     libpng \
-    liblog \
     libutils \
+    liblog \
     libcutils \
     libexpat \
     libziparchive-host \