CVE-2026-58938 AI-generated analysis
platform/frameworks/av, media/module/extractors/mp4 (libmp4extractor, MPEG4Source)
Adds a recursion depth parameter and a depth > 100 guard to MPEG4Source::parseChunk in the MP4 extractor so deeply nested boxes in a crafted MP4 file return ERROR_MALFORMED instead of recursing without bound.
Root cause
MPEG4Source::parseChunk in media/module/extractors/mp4/MPEG4Extractor.cpp recursively parses nested boxes: inside the moof/traf container handling it loops `while (*offset < stop_offset)` calling parseChunk(offset), and in the trailing scan it calls parseChunk(offset) again when it encounters an mdat box. Neither call site tracked recursion depth, so a file with excessively nested boxes (the commit message gives moof->traf->moof as an example) drives unbounded recursion and stack exhaustion, crashing the media process (mediaserver per the commit message). The sibling MPEG4Extractor::parseChunk already had a depth guard; MPEG4Source::parseChunk did not. Additionally, on 14/15/16 the mdat call site discarded the return status of the recursive parseChunk and did not require chunk_size > 0.
How the fix works
- MPEG4Extractor.cpp, class MPEG4Source private declaration: signature changed from parseChunk(off64_t *offset) to parseChunk(off64_t *offset, int depth = 0), so existing callers keep compiling and start at depth 0.
- MPEG4Extractor.cpp:MPEG4Source::parseChunk: new first statement `if (depth > 100) return ERROR_MALFORMED;` before the header read, bounding recursion to 101 nested levels.
- MPEG4Extractor.cpp:MPEG4Source::parseChunk, container loop (`while (*offset < stop_offset)`): recursive call changed to parseChunk(offset, depth + 1); the existing error propagation is kept.
- MPEG4Extractor.cpp:MPEG4Source::parseChunk, trailing scan mdat branch: condition tightened to `chunk_type == FOURCC("mdat") && chunk_size > 0`, recursive call changed to parseChunk(offset, depth + 1), and its status is now captured and returned on error instead of being ignored (on Android 17 the chunk_size > 0 check and error propagation were already present, so only the depth argument was added there).
Completeness
- Both recursive call sites inside MPEG4Source::parseChunk now pass depth + 1 and are covered by the single entry guard; the guard runs before any I/O so a too-deep call fails immediately.
- The guard only covers MPEG4Source::parseChunk. The commit message states MPEG4Extractor::parseChunk already has an equivalent guard; the material does not show that code, so it is not verified here.
- The mdat branch now also rejects zero-size mdat boxes (chunk_size > 0) and propagates errors from the nested parse, which previously were silently dropped; with chunk_size == 0 the following `else if (chunk_size == 0) break;` branch is taken instead.
- The limit of 100 is a fixed constant; no configuration or per-box-type nuance.
Behavior changes
- MPEG4Source::parseChunk returns ERROR_MALFORMED when nesting depth exceeds 100, which propagates to the caller and aborts parsing of that fragment.
- Errors from parsing an mdat box reached in the trailing scan are now returned to the caller rather than ignored.
- An mdat box with chunk_size == 0 in the trailing scan no longer triggers a recursive parse; it falls through to the chunk_size == 0 break.
Per major
- Android 14: same fix: platform/frameworks/av 5890f53af9a6 in android-security-14.0.0_r31, identical hunks (depth parameter, guard, both call sites, mdat chunk_size > 0 and error propagation); 7/8 patched lines present at that tag.
- Android 15: same fix: platform/frameworks/av 1cc0198240e6 in android-security-15.0.0_r19, the reference diff; 7/8 patched lines present at that tag.
- Android 16: same fix: platform/frameworks/av 41bfe34e8961 in android-security-16.0.0_r10, identical hunks at shifted line numbers; 7/8 patched lines present at that tag.
- Android 17: adapted fix: platform/frameworks/av d59eebe22778 in android-security-17.0.0_r3; the mdat branch already had `chunk_size > 0` and error propagation, so only the depth parameter, guard, and depth + 1 arguments were added; 7/8 patched lines present at that tag.
Unknowns
- The entry point inside MPEG4Source that first calls parseChunk is not shown in the material.
- The contents of the existing depth guard in MPEG4Extractor::parseChunk referenced by the commit message are not shown.
- Which single line of the 8-line patched region is reported as not present at each tag is not identified in the per-major facts.