Closed Bug 2010933 (CVE-2026-2759) Opened 10 months ago Closed 10 months ago

Out-of-bounds read in AVIFDecoderStream::ReadAt due to missing offset validation

Categories

(Core :: Graphics: ImageLib, defect)

defect

Tracking

()

RESOLVED FIXED
149 Branch
Tracking Status
firefox-esr115 148+ fixed
firefox-esr140 148+ fixed
firefox147 --- wontfix
firefox148 + fixed
firefox149 + fixed

People

(Reporter: stevenjulian1528, Assigned: tnikkel)

References

(Regression)

Details

(4 keywords, Whiteboard: [client-bounty-form][adv-main148+][adv-esr115.33+] [adv-esr140.8+])

Attachments

(4 external files, 2 obsolete files)

Description

AVIFDecoderStream::ReadAt computes the read size using mBuffer->length() - offset without validating offset. If offset is negative or greater than the buffer length, the subtraction underflows/overflows and size remains large, leading to memcpy reading past the end of mBuffer. This is an out‑of‑bounds read in a code path processing untrusted AVIF input.

Affected Code

  • image/decoders/nsAVIFDecoder.cpp:140 size = std::min(size, size_t(mBuffer->length() - offset)); ... memcpy(data, mBuffer->begin() + offset, size);
  • Reference for expected behavior: dom/media/mp4/BufferStream.cpp:19 validates offsets and returns NS_ERROR_DOM_MEDIA_RANGE_ERR.

Proof of Concept (minimal)

Vector<uint8_t> buffer;
buffer.append(0);
RefPtr<AVIFDecoderStream> stream = new AVIFDecoderStream(&buffer);
uint8_t out = 0;
size_t bytes = 0;
stream->ReadAt(2, &out, sizeof(out), &bytes);

This triggers an out‑of‑bounds read because offset is beyond buffer.length().

Suggested Fix

Add range checks before computing the remaining length, similar to BufferStream::ReadAt: if (offset < 0 || uint64_t(offset) > mBuffer->length()) { return NS_ERROR_DOM_MEDIA_RANGE_ERR; } size_t remaining = mBuffer->length() - size_t(offset); size = std::min(size, remaining); if (size == 0) { return NS_ERROR_DOM_MEDIA_RANGE_ERR; }

Notes

  • This bug is in the AVIF ByteStream adapter and is not aligned with other ByteStream implementations that validate offsets.
  • I’m preparing an ASan-only gtest to make this deterministic, but in my current headless VM environment the Firefox gtest harness aborts before executing any tests due to an ASan runtime thread-interceptor issue (‘Joining already joined thread’ / pthread intercept failure in glib). I’ll attach the ASan crash log / gtest output from a compatible environment as follow-up.
Flags: sec-bounty?
Group: firefox-core-security → media-core-security
Component: Security → Audio/Video: Playback
Keywords: csectype-bounds
Product: Firefox → Core

convenience links for the references in "Affected Code" above

image/decoders/nsAVIFDecoder.cpp:140 size = std::min(size, size_t(mBuffer->length() - offset)); ... memcpy(data, mBuffer->begin() + offset, size);

https://searchfox.org/firefox-main/rev/d7b112b2ff492134ce4e4d2862351cd393320136/image/decoders/nsAVIFDecoder.cpp#142,148

dom/media/mp4/BufferStream.cpp:19 validates offsets and returns NS_ERROR_DOM_MEDIA_RANGE_ERR.

https://searchfox.org/firefox-main/rev/d7b112b2ff492134ce4e4d2862351cd393320136/dom/media/mp4/BufferStream.cpp#25-26

I think they did try to validate the offset with the "min(size, length-offset)" calculation. But length-offset gets cast to size_t so an out of bounds offset gives a huge value rather than a negative one. It appears they did expect a negative value for this case because the next line checks if (size <= 0) {, but of course that can't ever be negative because size is unsigned.

I don't know if this could be exploited in Gecko. I expect the places that call ReadAt() would only call it with a valid offset when they know there's unconsumed data in the buffer. Note that BufferStream needs more checks because it has an internal concept of mStartOffset to worry about.

Status: UNCONFIRMED → NEW
Ever confirmed: true
Flags: needinfo?(tnikkel)

(In reply to Daniel Veditz [:dveditz] from comment #1)

I don't know if this could be exploited in Gecko. I expect the places that call ReadAt() would only call it with a valid offset when they know there's unconsumed data in the buffer.

AFAICT the AVIFDecoderStream objects are only used via a SampleIterator object. That does some sanity checking itself, ie

https://searchfox.org/firefox-main/rev/d7b112b2ff492134ce4e4d2862351cd393320136/dom/media/mp4/SampleIterator.cpp#93
https://searchfox.org/firefox-main/rev/d7b112b2ff492134ce4e4d2862351cd393320136/dom/media/mp4/SampleIterator.cpp#117

so any potential attacker controlled offsets/lengths from the avif file would need to get through that or have some explanation of how it could get through (not saying it's impossible, just that it's a higher bar then just putting the offsets into the avif file to get this code to use it).

Assignee: nobody → tnikkel
Component: Audio/Video: Playback → Graphics: ImageLib
Keywords: regression
Regressed by: avis

Set release status flags based on info from the regressing bug 1788119

Flags: needinfo?(tnikkel)
Attached file (secure) —

SampleIterator does do a length check, but it only checks mByteRange.mEnd <= length and never validates mByteRange.mStart >= 0 or that the u64 offsets from mp4parse fit into int64. MP4SampleIndex just copies the u64 offsets into MediaByteRange without bounds checks, so overflow to negative is possible. If mEnd overflows negative, the end<=length check passes and ReadAt still sees an invalid offset. Since AVIFDecoderStream::ReadAt has no offset validation (unlike BufferStream), it’s still an OOB read. So this isn’t fully mitigated yet; I think ReadAt should still be hardened and/or SampleIterator should check start>=0 and range validity

Also, the sanity checks in SampleIterator only verify mByteRange.mEnd <= length (dom/media/mp4/SampleIterator.cpp:93, dom/media/mp4/SampleIterator.cpp:117). They do not enforce mByteRange.mStart >= 0, mByteRange.mStart <= mByteRange.mEnd, or that mp4parse’s u64 offsets fit into int64. Those u64 values are copied into MediaByteRange (int64) without bounds checks (dom/media/mp4/MP4Metadata.cpp:38, dom/media/mp4/SampleIterator.cpp:433.

MediaByteRange is Interval<int64_t> in dom/media/MediaResource.h:22), so values > INT64_MAX can wrap negative. In that case mEnd <= length still passes and ReadAt sees a negative offset. So the current sanity check doesn’t prevent the OOB read. ReadAt still needs its own range validation (like BufferStream).

Comment on attachment 9538364 [details]
(secure)

Security Approval Request

  • How easily could an exploit be constructed based on the patch?: probably pretty easy to get the OOB read, hard to disguise this, then they have to turn it into an exploit
  • Do comments in the patch, the check-in comment, or tests included in the patch paint a bulls-eye on the security problem?: Yes
  • Which branches (beta, release, and/or ESR) are affected by this flaw, and do the release status flags reflect this affected/unaffected state correctly?: all
  • If not all supported branches, which bug introduced the flaw?: Bug 1788119
  • Do you have backports for the affected branches?: No
  • If not, how different, hard to create, and risky will they be?: easy to create, the only change to this code was to change these functions to return an nsresult instead of a bool
  • How likely is this patch to cause regressions; how much testing does it need?: unlikely, only offsets/sizes that overflow are affected
  • Is the patch ready to land after security approval is given?: Yes
  • Is Android affected?: Yes
Attachment #9538364 - Flags: sec-approval?

This sounds like it is an out of bounds read, despite some existing checks, so I'll mark it sec-high.

Keywords: sec-high

Comment on attachment 9538364 [details]
(secure)

sec-approval+, a=dveditz

Attachment #9538364 - Flags: sec-approval? → sec-approval+
Attached file (secure) (obsolete) —
Attachment #9538957 - Flags: approval-mozilla-esr140?
Attached file (secure) (obsolete) —
Attachment #9538958 - Flags: approval-mozilla-esr115?
Attachment #9538958 - Attachment is obsolete: true
Attachment #9538958 - Flags: approval-mozilla-esr115?
Attachment #9538957 - Attachment is obsolete: true
Attachment #9538957 - Flags: approval-mozilla-esr140?
Attached file (secure) —
Attachment #9538959 - Flags: approval-mozilla-esr140?

firefox-esr140 Uplift Approval Request

  • User impact if declined: sec-high
  • Code covered by automated testing: yes
  • Fix verified in Nightly: no
  • Needs manual QE test: no
  • Steps to reproduce for manual QE testing: n/a
  • Risk associated with taking this patch: low
  • Explanation of risk level: handling various integer overflow cases that real content would not encounter
  • String changes made/needed: none
  • Is Android affected?: yes
Attached file (secure) —
Attachment #9538960 - Flags: approval-mozilla-esr115?

firefox-esr115 Uplift Approval Request

  • User impact if declined: sec-high
  • Code covered by automated testing: yes
  • Fix verified in Nightly: no
  • Needs manual QE test: no
  • Steps to reproduce for manual QE testing: n/a
  • Risk associated with taking this patch: low
  • Explanation of risk level: handling integer overflow real content would not encounter
  • String changes made/needed: none
  • Is Android affected?: yes

firefox-beta Uplift Approval Request

  • User impact if declined: sec-high
  • Code covered by automated testing: yes
  • Fix verified in Nightly: no
  • Needs manual QE test: no
  • Steps to reproduce for manual QE testing: n/a
  • Risk associated with taking this patch: low
  • Explanation of risk level: handling integer overflow that real content does not encounter
  • String changes made/needed: none
  • Is Android affected?: yes
Attachment #9538961 - Flags: approval-mozilla-beta?
Attached file (secure) —
Group: media-core-security → core-security-release
Status: NEW → RESOLVED
Closed: 10 months ago
Resolution: --- → FIXED
Target Milestone: --- → 149 Branch
Attachment #9538961 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
Flags: sec-bounty? → sec-bounty+
QA Whiteboard: [sec] [uplift] [qa-triage-done-c149/b148]
Attachment #9538959 - Flags: approval-mozilla-esr140? → approval-mozilla-esr140+
Attachment #9538960 - Flags: approval-mozilla-esr115? → approval-mozilla-esr115+

Hi team, sorry to bother. This is my first time receiving a bounty, and I'm a bit unsure about the next steps.

I’ve marked it as sec-bounty+, but I haven't received an email regarding the payment process or documentation yet. Could you please advise if there's anything I need to fill out or if there's a typical timeline for processing? Thank you

Flags: needinfo?(dveditz)

The security team is temporarily short-staffed and swamped and bounty processing time is far from normal. Please hang on a bit longer.

Flags: needinfo?(dveditz)

So, i don't need to fill any informations for bounty processing? Or do you need me to fill any docs?

Flags: needinfo?(dveditz)
Whiteboard: [client-bounty-form] → [adv-main148+]
Whiteboard: [adv-main148+] → [client-bounty-form][adv-main148+]
Whiteboard: [client-bounty-form][adv-main148+] → [client-bounty-form][adv-main148+][adv-esr115.33+]
Whiteboard: [client-bounty-form][adv-main148+][adv-esr115.33+] → [client-bounty-form][adv-main148+][adv-esr115.33+] [adv-esr140.8+]
Alias: CVE-2026-2759

It has been over a month since the bounty determined, but I haven't received email payment for bounty untill now. I just want to remind guys

also guys can you edit my name in security advisories firefox from stevej to Steven Julian?

See Also: → 2037505
Group: core-security-release
Duplicate of this bug: 2037505
Flags: needinfo?(dveditz)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: