Skip to content

Commit

Permalink
Limit allocations to avoid out-of-memory
Browse files Browse the repository at this point in the history
Corrupt files could cause very large allocations, limit them to something
more reasonable.

Bug: 17769851
Change-Id: Ib0f722fd6fddff873bd7a547aac456e608c34c84
(cherry picked from commit dedaca6)
  • Loading branch information
marcone authored and andi34 committed Jun 7, 2016
1 parent b820d9c commit 63f26e4
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions media/libstagefright/MPEG4Extractor.cpp
Expand Up @@ -2504,16 +2504,24 @@ status_t MPEG4Source::start(MetaData *params) {
mWantsNALFragments = false;
}

int32_t tmp;
CHECK(mFormat->findInt32(kKeyMaxInputSize, &tmp));
size_t max_size = tmp;

// A somewhat arbitrary limit that should be sufficient for 8k video frames
// If you see the message below for a valid input stream: increase the limit
if (max_size > 64 * 1024 * 1024) {
ALOGE("bogus max input size: %zu", max_size);
return ERROR_MALFORMED;
}
mGroup = new MediaBufferGroup;

int32_t max_size;
CHECK(mFormat->findInt32(kKeyMaxInputSize, &max_size));

mGroup->add_buffer(new MediaBuffer(max_size));

mSrcBuffer = new (std::nothrow) uint8_t[max_size];
if (mSrcBuffer == NULL) {
// file probably specified a bad max size
delete mGroup;
mGroup = NULL;
return ERROR_MALFORMED;
}

Expand Down

0 comments on commit 63f26e4

Please sign in to comment.