Skip to content

Commit

Permalink
Limit mp4 atom size to something reasonable
Browse files Browse the repository at this point in the history
CYNGNOS-3303
Bug: 28615448
Change-Id: I5916f6839b4a9bbee4388a106e7373bcd4154f5a
(cherry picked from commit cb898dc)
  • Loading branch information
marcone authored and Jessica Wagantall committed Nov 16, 2016
1 parent 09a3abc commit 65a3e27
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions media/libstagefright/MPEG4Extractor.cpp
Expand Up @@ -100,6 +100,12 @@

namespace android {

enum {
// maximum size of an atom. Some atoms can be bigger according to the spec,
// but we only allow up to this size.
kMaxAtomSize = 64 * 1024 * 1024,
};

class MPEG4Source : public MediaSource {
public:
// Caller retains ownership of both "dataSource" and "sampleTable".
Expand Down Expand Up @@ -941,6 +947,13 @@ status_t MPEG4Extractor::parseChunk(off64_t *offset, int depth) {
PathAdder autoAdder(&mPath, chunk_type);

off64_t chunk_data_size = *offset + chunk_size - data_offset;
if (chunk_type != FOURCC('m', 'd', 'a', 't') && chunk_data_size > kMaxAtomSize) {
char errMsg[100];
sprintf(errMsg, "%s atom has size %" PRId64, chunk, chunk_data_size);
ALOGE("%s (b/28615448)", errMsg);
android_errorWriteWithInfoLog(0x534e4554, "28615448", -1, errMsg, strlen(errMsg));
return ERROR_MALFORMED;
}

if (chunk_type != FOURCC('c', 'p', 'r', 't')
&& chunk_type != FOURCC('c', 'o', 'v', 'r')
Expand Down

0 comments on commit 65a3e27

Please sign in to comment.