Open Bug 2056822 Opened 3 months ago Updated 1 day ago

Crash in [@ mozilla::CheckedInt<T>::value | mozilla::media::TimeUnit::operator<T>]

Categories

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

defect

Tracking

()

Tracking Status
firefox-esr140 --- unaffected
firefox-esr153 --- fix-optional
firefox153 --- fix-optional
firefox154 --- wontfix
firefox155 --- fix-optional

People

(Reporter: gsvelto, Unassigned, NeedInfo)

References

(Regression)

Details

(Keywords: crash, regression)

Crash Data

Crash report: https://crash-stats.mozilla.org/report/index/1522d439-1e76-454a-b7a4-0e5ff0260721

MOZ_CRASH Reason:

MOZ_RELEASE_ASSERT(mIsValid) (Invalid checked integer (division by zero or integer overflow))

Top 10 frames:

0  XUL  MOZ_CrashSequence(void*, long)  mfbt/Assertions.h:266
0  XUL  mozilla::CheckedInt<long long>::value() const  mfbt/CheckedInt.h:324
0  XUL  mozilla::media::TimeUnit::operator<=(mozilla::media::TimeUnit const&) const  dom/media/TimeUnits.cpp:235
1  XUL  mozilla::media::Interval<mozilla::media::TimeUnit>::TouchesOnRight(mozilla::m...  dom/media/Intervals.h:219
2  XUL  mozilla::media::IntervalSet<mozilla::media::TimeUnit>::Add(mozilla::media::In...  dom/media/Intervals.h:330
3  XUL  mozilla::media::IntervalSet<mozilla::media::TimeUnit>::operator+=(mozilla::me...  dom/media/Intervals.h:370
3  XUL  mozilla::media::TimeIntervals::ToMicrosecondResolution() const  dom/media/TimeUnits.h:325
4  XUL  mozilla::dom::SourceBuffer::GetBuffered(mozilla::ErrorResult&)  dom/media/mediasource/SourceBuffer.cpp:134
5  XUL  mozilla::dom::SourceBuffer_Binding::get_buffered(JSContext*, JS::Handle<JSObj...  dom/bindings/SourceBufferBinding.cpp:194
6  ?  @0x000007d1304b6cdc

This crash appears to be a regression and is now rapidly rising in volume, however it might be hard to spot where it began. We had very sporadic crashes in the past, like once a week, with the first affected builid being 20260227092902 (this could be accidental though, as it's from the oldest crashes we have on file and will soon be purged from our servers). Things changes with the release of version 150.0.0. Crashes on desktop ramp up from once a week to several per day, once per day on mobile. This stays steady for a while then volume ramps up significantly in the past few days. We had 626 crashes in the past two weeks with 349 crash reports in the past three days alone, most of them from mobile users.

Looking at the comments and URLs these appear to be the websites that are most likely to trigger the issue:

This is likely a regression from bug 2014895, and it's an incomplete-fix problem rather than bad media data alone.

Mechanism

TimeUnit stores time as a CheckedInt<int64_t> mTicks over a base. The comparison operators guard validity only with a debug-only MOZ_ASSERT(IsValid() && aOther.IsValid()) and then dereference mTicks.value(), which carries a release assert:

https://searchfox.org/firefox-main/rev/9f4db3078551c6d54c40f3de27b603f52b89d35a/dom/media/TimeUnits.cpp#L232-235

So in release builds any invalid TimeUnit that reaches a comparison is a guaranteed MOZ_RELEASE_ASSERT(mIsValid) crash.

The invalid TimeUnit is produced by TimeUnit::ToBase(), which returns TimeUnit::Invalid() when the value converted to the target base overflows int64 (a time exceeding ~292,000 years in microseconds — reachable with the extreme/inconsistent timestamps these live-stream sites produce):

https://searchfox.org/firefox-main/rev/9f4db3078551c6d54c40f3de27b603f52b89d35a/dom/media/TimeUnits.h#L233-237

The crashing path from comment 0 is SourceBuffer::GetBuffered -> TimeIntervals::ToMicrosecondResolution(), which calls ToBase(USECS_PER_S) on each interval endpoint and stores the result without checking IsValid():

https://searchfox.org/firefox-main/rev/9f4db3078551c6d54c40f3de27b603f52b89d35a/dom/media/TimeUnits.h#L317-327

The resulting invalid endpoint is then compared during normalization in Interval::TouchesOnRight -> operator<=, which crashes:

https://searchfox.org/firefox-main/rev/9f4db3078551c6d54c40f3de27b603f52b89d35a/dom/media/Intervals.h#L218-222

Why it regressed

Bug 2014895 (landed 2026-02-12) introduced the return TimeUnit::Invalid() path in ToBase. It guarded the two callers it knew about — operator+ and operator- got && inBase.IsValid() — but every other ToBase consumer still uses the result directly, including TimeIntervals::ToMicrosecondResolution / TimeIntervals::ToBase, MediaSource::DurationChange (highestEndTime.ToBase(USECS_PER_S)), TrackBuffersManager, and MediaDecoderStateMachine. Before bug 2014895 the same overflow went through AssertedCast, which in release is a plain cast — a garbage-but-valid value, so comparisons did not assert. The fix traded silent UB for a hard crash on the unguarded call sites.

Timeline matches: first affected build is 20260227092902, right after the 2026-02-12 landing; it rode to release with 150 and has been ramping with exposure since (no second code change needed to explain the rise).

Volume

~630 crashes / 2 weeks, split roughly evenly between Firefox desktop and Fenix. Windows/macOS/Linux + Android; not hardware- or OS-specific. All content-process, during MSE playback on live-TV streams.

Suggested fix

Make ToBase clamp an out-of-range conversion to +/-Infinity (a valid TimeUnit all operators already handle) instead of returning Invalid(); there is precedent in FromSeconds (bug 1835075). This protects all call sites at once. Needs checking against the FLAC subtraction scenario from bug 2014895, which relied on Invalid() + non-zero aOutError to force the float fallback in operator±. The narrower alternative is to make the remaining ToBase consumers validity-aware like operator± already are.

Keywords: regression
Regressed by: 2014895

:padenot, since you are the author of the regressor, bug 2014895, could you take a look? Also, could you set the severity field?

For more information, please visit BugBot documentation.

Flags: needinfo?(padenot)
Group: core-security

I am not sure why the other bug is still hidden, but for caution I am hiding this one, too.

Let's just unhide this for greater visibility. I was about to refile it myself. The other bug probably doesn't even need to be hidden, and this one is a release assert so even less so.

Group: core-security

At least looking at the last week, 100% of these signatures have SourceBuffer_Binding::get_buffered in the stack.

Severity: -- → S3
Priority: -- → P3
Duplicate of this bug: 2073306

Copying crash signatures from duplicate bugs.

Crash Signature: [@ mozilla::CheckedInt<T>::value | mozilla::media::TimeUnit::operator<T>] → [@ mozilla::CheckedInt<T>::value | mozilla::media::TimeUnit::operator<T>] [@ mozilla::CheckedInt<T>::value | mozilla::media::TimeUnit::operator<=]
See Also: → 2093511
You need to log in before you can comment on or make changes to this bug.