Open Bug 2072335 Opened 2 months ago Updated 1 day ago

Firefox crashes (native stack overflow) when opening any page with a crafted MP4/M4A file containing a deeply-nested ES_Descriptor in its esds box

Categories

(Core :: Audio/Video: Playback, defect, P3)

defect

Tracking

()

ASSIGNED

People

(Reporter: theeldruin, Assigned: kinetik)

References

Details

(Keywords: reporter-external, Whiteboard: [deduped][nosec])

Attachments

(1 file)

67.38 KB, application/zip
Details
Attached file poc(2).zip —

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:140.0) Gecko/20100101 Firefox/140.0

Steps to reproduce:

  1. Open the attached poc_esds_recursion_depth8000.html (or host it and poc_esds_recursion_depth8000.mp4 on any web server) in Firefox.

Actual results:

Firefox crashes (tab crash and/or full browser crash) when trying to load the attached page/file.

Root cause: the mp4parse crate's esds box (elementary stream descriptor, used by AAC/MP3/MP4V audio and video tracks) is parsed by mutually recursive functions in mp4parse/src/lib.rs with no depth limit:

  • find_descriptor() (line 5145) dispatches by tag to read_es_descriptor()/read_dc_descriptor()
  • read_es_descriptor() (line 5488) and read_dc_descriptor() (line 5440) each call back into find_descriptor() on their own remaining payload bytes (the nested descriptor)

None of the three function signatures carry a depth counter, and none of the length/bounds checks in the loop constrain recursion depth -- they only validate that each descriptor's declared length fits the bytes available at that level, which a deeply-nested but well-formed chain trivially satisfies at any depth.

I confirmed this at three levels:

  1. Added a #[test] directly to mp4parse's own tests.rs calling the real, unmodified find_descriptor() with a synthetic nested-descriptor buffer: 5,000 levels (32KB) parses fine, 8,000 levels (53KB) overflows the stack and aborts (SIGABRT) -- see attached poc_nested_es_descriptor_test.rs / poc_output.txt.
  2. Built a complete, valid MP4 container around the same malicious descriptor payload at depth=200 (control) and depth=8000, with an accompanying minimal HTML page (<audio>/<video> tags) -- attached (poc_esds_recursion_depth200.mp4/.html, poc_esds_recursion_depth8000.mp4/.html). Independently sanity-checked the container's validity with mutagen (an unrelated Python MP4 parser), which walks the box hierarchy correctly down to the esds box before cleanly rejecting the deliberately-malformed nested tag structure -- confirming the container itself is well-formed up to exactly the adversarial part.
  3. Opened both HTML pages in a real, released Firefox: the depth=200 control did NOT crash; the depth=8000 version DID crash the browser for real. Only the nesting depth differs between the two files, ruling out "any malformed MP4" as an alternate explanation.

Expected results:

A crafted media file should never be able to crash the browser via unbounded native recursion. The find_descriptor/read_es_descriptor/read_dc_descriptor mutual recursion should be converted to an iterative traversal using an explicit heap-allocated work list, or, as a cheaper mitigation, nesting depth should be capped with a counter (real-world ES_Descriptor structures never nest anywhere close to a few hundred levels deep, let alone thousands) and rejected as a clean parse error past that limit.

Group: firefox-core-security → media-core-security
Component: Untriaged → Audio/Video: Playback
Product: Firefox → Core

This duplicate check has been performed by our automated bug triage tool (currently under development). No validation or verification has been performed.

Bugs considered:

  • bug 1387739 — similar symptoms but a different root cause
  • bug 1184871 — similar symptoms but a different root cause
  • bug 1186718 — similar symptoms but a different root cause
  • bug 2026182 — similar symptoms but a different root cause

Confidence: 80%

Whiteboard: [deduped] → [deduped][nosec]

This rating has been determined by our automated bug rating tool (currently under development). No validation or verification has been performed.

Confidence: 78%

Stack exhaustion isn't a security issue.

Group: media-core-security

The severity field is not set for this bug.
:jimm, could you have a look please?

For more information, please visit BugBot documentation.

Flags: needinfo?(jmathies)

Not sec, but maybe a denial of service type issue? Worth investigating.

Flags: needinfo?(jmathies) → needinfo?(karlt)

The MPEG4 box structure naturally leads to recursive algorithms.
These could be rewritten as iterative algorithms, but might be harder to follow.
Alternatively, a depth limit could be applied.
Unlikely to be reached with media files that are not trying to crash the content process in which they are loaded.

Severity: -- → S4
Status: UNCONFIRMED → NEW
Ever confirmed: true
Flags: needinfo?(karlt)
Priority: -- → P3
Assignee: nobody → kinetik
Status: NEW → ASSIGNED
Duplicate of this bug: 2097763
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: