diff options
author | Jon Larimer <jlarimer@google.com> | 2015-08-18 14:25:45 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-08-18 14:25:45 +0000 |
commit | 0d46c93785e2c426be11172bec0489b698fea6c3 (patch) | |
tree | d85768c73eae26399e188ee1fa069b7aac04c7ea /media | |
parent | aa1cc74139341eb3ae9511af5310b965dbf890f4 (diff) | |
parent | f810a8298aea13fa177060cdc10c8297eac69c49 (diff) | |
download | frameworks_av-0d46c93785e2c426be11172bec0489b698fea6c3.zip frameworks_av-0d46c93785e2c426be11172bec0489b698fea6c3.tar.gz frameworks_av-0d46c93785e2c426be11172bec0489b698fea6c3.tar.bz2 |
Merge "MPEG4Source::fragmentedRead: check range before writing into buffers" into klp-dev
Diffstat (limited to 'media')
-rw-r--r-- | media/libstagefright/MPEG4Extractor.cpp | 48 |
1 files changed, 40 insertions, 8 deletions
diff --git a/media/libstagefright/MPEG4Extractor.cpp b/media/libstagefright/MPEG4Extractor.cpp index 7945ec9..0899362 100644 --- a/media/libstagefright/MPEG4Extractor.cpp +++ b/media/libstagefright/MPEG4Extractor.cpp @@ -3475,6 +3475,14 @@ status_t MPEG4Source::fragmentedRead( if (!mIsAVC || mWantsNALFragments) { if (newBuffer) { + if (!isInRange((size_t)0u, mBuffer->size(), size)) { + mBuffer->release(); + mBuffer = NULL; + + ALOGE("fragmentedRead ERROR_MALFORMED size %zu", size); + return ERROR_MALFORMED; + } + ssize_t num_bytes_read = mDataSource->readAt(offset, (uint8_t *)mBuffer->data(), size); @@ -3482,7 +3490,7 @@ status_t MPEG4Source::fragmentedRead( mBuffer->release(); mBuffer = NULL; - ALOGV("i/o error"); + ALOGE("i/o error"); return ERROR_IO; } @@ -3552,18 +3560,40 @@ status_t MPEG4Source::fragmentedRead( ssize_t num_bytes_read = 0; int32_t drm = 0; bool usesDRM = (mFormat->findInt32(kKeyIsDRM, &drm) && drm != 0); + void *data = NULL; + bool isMalFormed = false; if (usesDRM) { - num_bytes_read = - mDataSource->readAt(offset, (uint8_t*)mBuffer->data(), size); + if (mBuffer == NULL || !isInRange((size_t)0u, mBuffer->size(), size)) { + isMalFormed = true; + } else { + data = mBuffer->data(); + } } else { - num_bytes_read = mDataSource->readAt(offset, mSrcBuffer, size); + int32_t max_size; + if (mFormat == NULL + || !mFormat->findInt32(kKeyMaxInputSize, &max_size) + || !isInRange((size_t)0u, (size_t)max_size, size)) { + isMalFormed = true; + } else { + data = mSrcBuffer; + } } + if (isMalFormed || data == NULL) { + ALOGE("isMalFormed size %zu", size); + if (mBuffer != NULL) { + mBuffer->release(); + mBuffer = NULL; + } + return ERROR_MALFORMED; + } + num_bytes_read = mDataSource->readAt(offset, data, size); + if (num_bytes_read < (ssize_t)size) { mBuffer->release(); mBuffer = NULL; - ALOGV("i/o error"); + ALOGE("i/o error"); return ERROR_IO; } @@ -3577,16 +3607,18 @@ status_t MPEG4Source::fragmentedRead( size_t dstOffset = 0; while (srcOffset < size) { - bool isMalFormed = !isInRange(0u, size, srcOffset, mNALLengthSize); + isMalFormed = !isInRange((size_t)0u, size, srcOffset, mNALLengthSize); size_t nalLength = 0; if (!isMalFormed) { nalLength = parseNALSize(&mSrcBuffer[srcOffset]); srcOffset += mNALLengthSize; - isMalFormed = !isInRange(0u, size, srcOffset, nalLength); + isMalFormed = !isInRange((size_t)0u, size, srcOffset, nalLength) + || !isInRange((size_t)0u, mBuffer->size(), dstOffset, (size_t)4u) + || !isInRange((size_t)0u, mBuffer->size(), dstOffset + 4, nalLength); } if (isMalFormed) { - ALOGE("Video is malformed"); + ALOGE("Video is malformed; nalLength %zu", nalLength); mBuffer->release(); mBuffer = NULL; return ERROR_MALFORMED; |