OSDN Git Service

Prevent reading past the end of the buffer in 3GPP
authorJoshua J. Drake <android-open-source@qoop.org>
Mon, 4 May 2015 22:33:49 +0000 (17:33 -0500)
committerWei Jia <wjia@google.com>
Wed, 3 Jun 2015 23:20:56 +0000 (23:20 +0000)
Metadata processed within the parse3GPPMetaData function may not be NUL
terminated and thus calling setCString may read out of bounds. Ensure
proper NUL termination, but take care not to interfere with other special
cases (ie, albm).

Bug: 20923261
Change-Id: Ie93b3038b534b4c4460571a68f4d734cff7ad324
(cherry picked from commit 5cea0155cfc41f67e91343c342f44251c03fde3a)

media/libstagefright/MPEG4Extractor.cpp

index 080dcd1..095b9dd 100644 (file)
@@ -2395,11 +2395,11 @@ status_t MPEG4Extractor::parseITunesMetaData(off64_t offset, size_t size) {
 }
 
 status_t MPEG4Extractor::parse3GPPMetaData(off64_t offset, size_t size, int depth) {
-    if (size < 4) {
+    if (size < 4 || size == SIZE_MAX) {
         return ERROR_MALFORMED;
     }
 
-    uint8_t *buffer = new (std::nothrow) uint8_t[size];
+    uint8_t *buffer = new (std::nothrow) uint8_t[size + 1];
     if (buffer == NULL) {
         return ERROR_MALFORMED;
     }
@@ -2491,6 +2491,7 @@ status_t MPEG4Extractor::parse3GPPMetaData(off64_t offset, size_t size, int dept
         }
 
         if (isUTF8) {
+            buffer[size] = 0;
             mFileMetaData->setCString(metadataKey, (const char *)buffer + 6);
         } else {
             // Convert from UTF-16 string to UTF-8 string.