Skip to content

Commit 59aed18

Browse files
marconeandi34
authored andcommitted
Extra sanity checks on sample size and resolution
Instead of rejecting the samples later when they don't fit in the buffer, reject the entire file early. Bug: 22882938 Change-Id: I748153b0e9e827e3f2526468756295b4b5000de6 (cherry picked from commit beef7e5)
1 parent 3b7cb64 commit 59aed18

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

media/libstagefright/MPEG4Extractor.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,15 +1383,27 @@ status_t MPEG4Extractor::parseChunk(off64_t *offset, int depth) {
13831383
// each chunk originally prefixed with a 2 byte length will
13841384
// have a 4 byte header (0x00 0x00 0x00 0x01) after conversion,
13851385
// and thus will grow by 2 bytes per chunk.
1386+
if (max_size > SIZE_MAX - 10 * 2) {
1387+
ALOGE("max sample size too big: %zu", max_size);
1388+
return ERROR_MALFORMED;
1389+
}
13861390
mLastTrack->meta->setInt32(kKeyMaxInputSize, max_size + 10 * 2);
13871391
} else {
13881392
// No size was specified. Pick a conservatively large size.
1389-
int32_t width, height;
1390-
if (!mLastTrack->meta->findInt32(kKeyWidth, &width) ||
1391-
!mLastTrack->meta->findInt32(kKeyHeight, &height)) {
1393+
uint32_t width, height;
1394+
if (!mLastTrack->meta->findInt32(kKeyWidth, (int32_t*)&width) ||
1395+
!mLastTrack->meta->findInt32(kKeyHeight,(int32_t*) &height)) {
13921396
ALOGE("No width or height, assuming worst case 1080p");
13931397
width = 1920;
13941398
height = 1080;
1399+
} else {
1400+
// A resolution was specified, check that it's not too big. The values below
1401+
// were chosen so that the calculations below don't cause overflows, they're
1402+
// not indicating that resolutions up to 32kx32k are actually supported.
1403+
if (width > 32768 || height > 32768) {
1404+
ALOGE("can't support %u x %u video", width, height);
1405+
return ERROR_MALFORMED;
1406+
}
13951407
}
13961408

13971409
const char *mime;

0 commit comments

Comments
 (0)