Closed Bug 2040640 Opened 6 months ago Closed 6 months ago

Heap out-of-bounds write in VideoFrame::CreateBlackImage when MediaRecorder records a disabled captured video track

Categories

(Core :: Audio/Video: Recording, defect)

Firefox 150
defect

Tracking

()

RESOLVED DUPLICATE of bug 2024441
151 Branch
Tracking Status
firefox-esr115 --- wontfix
firefox-esr140 --- fixed
firefox151 --- fixed

People

(Reporter: lucasmontesheredero, Assigned: jhlin)

References

Details

(Keywords: reporter-external)

Attachments

(1 file, 1 obsolete file)

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

Steps to reproduce:

I believe this is a security-sensitive content-process memory corruption issue reachable from a normal web page.

A normal web page can trigger the issue by:

  1. Loading the attached malformed HEVC MP4 sample.
  2. Capturing the video with HTMLVideoElement.captureStream().
  3. Starting MediaRecorder on the captured stream.
  4. Disabling the captured video track.

Minimal local reproduction:

python3 -m http.server 8768 --bind 127.0.0.1

Then open:

http://127.0.0.1:8768/trigger.html?beacon=1&file=hevc_sar_14729x1_alloc72832.mp4&disable=before&timeslice=100

The crash-only reproduction uses:

trigger.html
hevc_sar_14729x1_alloc72832.mp4

Actual results:

The Web Content process crashes with SIGSEGV.

The affected path reaches VideoFrame::CreateBlackImage() from the MediaRecorder disabled captured video track path:

HTMLVideoElement with malformed HEVC MP4
-> captureStream()
-> MediaRecorder(stream, { mimeType: "video/webm;codecs=vp8" })
-> captured video track disabled
-> VP8TrackEncoder::PrepareRawFrame()
-> VideoFrame::CreateBlackImage(intrinsicSize)

In affected Release/ESR source, dom/media/VideoSegment.cpp computes plane sizes with unchecked int arithmetic:

int yLen = aSize.width * aSize.height;
int cbcrLen = cbcrSize.width * cbcrSize.height;

Then it allocates yLen + 2 * cbcrLen and calls memset() using the overflowed values.

In my debugger run, the vulnerable memset had:

allocated frame size: 0x11c80 bytes
first memset length: 0x55561300 bytes
write byte: 0x10

This produces a large deterministic heap out-of-bounds write. I also observed browser-managed AudioData metadata corruption before process termination,
so I believe this is stronger than a simple DoS.

Expected results:

Firefox should reject unsafe media/intrinsic dimensions before creating the synthetic black frame.

VideoFrame::CreateBlackImage() should validate dimensions and compute yLen, cbcrLen, and the final frame length with checked arithmetic before
allocation and memset().

The malformed media sample should not cause a content-process heap out-of-bounds write or crash.

I checked newer branches: Beta 151.0b10 / mozilla-central appear to contain checked integer validation in VideoFrame::CreateBlackImage(), and Nightly
153.0a1 did not crash with this exact PoC. However, current supported Release 150.0.3 and ESR 140.10.2esr still reproduce the crash, so this likely
needs security triage and uplift/backport assessment for supported branches.

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

Your write-up mentions trigger.html which isn't in your zip. Are there missing attachments, or can you give better instructions? We tried performing equivalent steps with the files in the archive but couldn't reproduce the problem. We don't know if that means the testcase is incomplete or we didn't understand the instructions, or we've fixed the bug.

If "Beta" 151 contained fixes then that is now "Release" 151, which would seem to mean we're done here.

Flags: needinfo?(lucasmontesheredero)
Assignee: nobody → jolin
Attached file (secure) (obsolete) —
Attachment #9591313 - Attachment is obsolete: true

It's fixed in bug 2024441 since release 151.

Status: UNCONFIRMED → RESOLVED
Closed: 6 months ago
Resolution: --- → FIXED
Group: media-core-security → core-security-release
Depends on: 2024441
Flags: needinfo?(lucasmontesheredero)
Target Milestone: --- → 151 Branch
Duplicate of bug: 2024441
Resolution: FIXED → DUPLICATE
Group: core-security-release
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: