OSDN Git Service

Prevent integer overflow when processing covr MPEG4 atoms
authorJoshua J. Drake <android-open-source@qoop.org>
Mon, 4 May 2015 23:36:35 +0000 (18:36 -0500)
committerWei Jia <wjia@google.com>
Wed, 3 Jun 2015 23:12:18 +0000 (16:12 -0700)
If the 'chunk_data_size' value is SIZE_MAX, an integer overflow will occur
and cause an undersized buffer to be allocated. The following processing
then overfills the resulting memory and creates a potentially exploitable
condition. Ensure that integer overflow does not occur.

Bug: 20923261
Change-Id: I75cce323aec04a612e5a230ecd7c2077ce06035f

media/libstagefright/MPEG4Extractor.cpp

index d52b605..4ef9fee 100644 (file)
@@ -1752,6 +1752,10 @@ status_t MPEG4Extractor::parseChunk(off64_t *offset, int depth) {
             if (mFileMetaData != NULL) {
                 ALOGV("chunk_data_size = %lld and data_offset = %lld",
                         chunk_data_size, data_offset);
+
+                if (chunk_data_size >= SIZE_MAX - 1) {
+                    return ERROR_MALFORMED;
+                }
                 sp<ABuffer> buffer = new ABuffer(chunk_data_size + 1);
                 if (mDataSource->readAt(
                     data_offset, buffer->data(), chunk_data_size) != (ssize_t)chunk_data_size) {