Crash in [@ mozilla::detail::InvalidArrayIndex_CRASH | nsTArray_Impl<T>::ElementAt | nsTArray_Impl<T>::operator[] | mozilla::dom::StyledRangeCollection::GetAbstractRangeAt]
Categories
(Core :: Layout, defect)
Tracking
()
People
(Reporter: clouseau-bot, Assigned: dholbert)
References
(Blocks 1 open bug, Regression)
Details
(Keywords: crash, regression)
Crash Data
Attachments
(1 file, 4 external files)
|
625 bytes,
text/html
|
Details |
Crash report: https://crash-stats.mozilla.org/report/index/534559b7-ae83-430c-bdcf-497720261103
MOZ_CRASH Reason:
ElementAt(aIndex = 57, aLength = 57)
Top 10 frames:
0 firefox-bin mozilla::detail::InvalidArrayIndex_CRASH(unsigned long, unsigned long) mfbt/Assertions.cpp:50
1 libxul.so mozilla::dom::Selection::Repaint(nsPresContext*) dom/base/Selection.cpp:2372
2 libxul.so nsFrameSelection::RepaintHighlightSelection(nsAtom*) layout/generic/nsFrameSelection.cpp:1744
3 libxul.so mozilla::dom::HighlightRegistry::RepaintAllHighlightSelections() dom/base/HighlightRegistry.cpp:135
4 libxul.so mozilla::RestyleManager::DoProcessPendingRestyles(mozilla::ServoTraversalFlags) layout/style/RestyleManager.cpp:3370
5 libxul.so mozilla::PresShell::DoFlushPendingNotifications(mozilla::ChangesToFlush) layout/base/PresShell.cpp:4673
6 libxul.so mozilla::dom::Document::FlushPendingNotifications(mozilla::ChangesToFlush) dom/base/Document.cpp:12133
7 libxul.so mozilla::dom::Element::GetBoundingClientRect() dom/base/Element.cpp:1199
8 libxul.so mozilla::dom::Element_Binding::getBoundingClientRect(JSContext*, JS::Handle<JSOb... dom/bindings/ElementBinding.cpp:4332
9 libxul.so mozilla::dom::binding_detail::GenericMethod<mozilla::dom::binding_detail::Normal... dom/bindings/BindingUtils.cpp:3218
There is 1 crash in nightly 161 with buildid 20261101085933.
In the last 30 days, Firefox has 21 crashes (from 19 installations) on release, 8 crashes (from 8 installations) on esr, 4 crashes (from 4 installations) on beta/DevEdition and 1 crash on nightly with this signature.
This signature has been reported since build 20260810162159 (2026-08-10), 83 days before the build above.
This bug looks actionable because:
-
Selection::Repaintcrashes indexingmStyledRangesatSelection.cpp:2372when a nested selection lookup duringSelectFramesremoves invalidStaticRanges from the same highlight selection's range array.RestyleManager::DoProcessPendingRestylesrepaints highlight selections viaHighlightRegistry::RepaintAllHighlightSelectionsandnsFrameSelection::RepaintHighlightSelection, which callsSelection::Repaint.RepaintcachesarrCount = mStyledRanges.Length()once and loopsi < arrCount, callingSelectFrames(..., *mStyledRanges.GetAbstractRangeAt(i), true).- For a text start node,
SelectFramescallsnsTextFrame::SelectionStateChanged. BecauseeHighlightis inkSelectionTypesWithDecorations, that callsCombineSelectionUnderlineRect, thenGetSelectionDetails, thennsFrameSelection::LookUpSelection. Selection::LookUpSelectionreachesStyledRanges::GetIndicesForInterval, which callsReorderRangesIfNecessary.- If the document generation changed since the last reorder,
ReorderRangesIfNecessarymoves every now-invalidStaticRangeout ofmRangeswithExtractElementAt, shrinking the array. - Back in
Repaint, the loop continues to the stalearrCountandGetAbstractRangeAt(57)hits the release bounds check on a 57-element array.
The crash reason
ElementAt(aIndex = 57, aLength = 57)shows the array was shorter than the loop bound cached at entry. The stack (a style flush fromgetBoundingClientRectinside a MutationObserver callback) fits a DOM mutation that invalidated a highlight'sStaticRangejust before the repaint. That invalidation is inferred, not observed. The owner should look first at makingRepaint, and other loops overmStyledRangesthat callSelectFrames, robust againstReorderRangesIfNecessarymutating the array during frame selection. -
The failing code comes from 25ade20bace1 (gh) (bug 1845446) by :jjaschke.
Impact
A content process crashes; the tabs it hosts show a crash page.
Possible fixes
- In
Selection::Repaint, possibly snapshot the ranges first so a nested reorder cannot invalidate the loop:AutoTArray<RefPtr<AbstractRange>, 4> ranges(mStyledRanges.Ranges()); for (const RefPtr<AbstractRange>& range : ranges) { nsresult rv = SelectFrames(aPresContext, *range, true); if (NS_FAILED(rv)) { return rv; } } - Alternatively, call
mStyledRanges.ReorderRangesIfNecessary()before the loop and/or re-checki < mStyledRanges.Length()on each iteration, and audit the similarSelectFrames(..., false)loop nearSelection.cpp:1602. - Longer term, it may help if the lookup path used during frame selection (
LookUpSelection) did not mutatemRanges, for example by deferring the invalid-static-range sweep out of read-only lookups.
How to confirm
A crashtest/WPT: register a Highlight holding many StaticRanges over text nodes, with a ::highlight() rule that sets text-decoration. Mutate the DOM so that some of those StaticRanges become invalid, then force a restyle that sets mNeedsPseudoElementSelectionsRepaint (for example by changing the highlight style and calling getBoundingClientRect()). The bounds crash in Selection::Repaint should reproduce.
Code references:
- nsTextFrame::SelectionStateChanged
- nsTextFrame::CombineSelectionUnderlineRect
- mozilla::dom::Selection::LookUpSelection
- mozilla::dom::Selection::StyledRanges::ReorderRangesIfNecessary
- layout/generic/nsTextFrame.cpp:6168
:jjaschke, can you have a look please?
Filed automatically by Clouseau with an LLM, from a submitted crash report: not an independent Mozilla discovery
Filed automatically by Clouseau, which analyses nightly crashes with an LLM. Nothing above was written or checked by a human. Please close it as INVALID if it is wrong — that is useful feedback, not a nuisance.
This is not an independent Mozilla discovery: the crash is known here only because somebody submitted the crash report linked at the top. If this duplicates an existing report, please resolve THIS bug as the duplicate and leave the credit with the earlier reporter.
| Reporter | ||
Comment 1•14 days ago
|
||
Crash report: https://crash-stats.mozilla.org/report/index/86435b65-52b7-4611-b66c-e13960261103
Reports with a different stack in the same spike: https://crash-stats.mozilla.org/report/index/751c4fb0-7835-457a-9a80-7ca6e0261103, https://crash-stats.mozilla.org/report/index/2074c5b8-76de-4294-be57-4244c0261104
MOZ_CRASH Reason:
ElementAt(aIndex = 292, aLength = 292)
Top 10 frames:
0 mozglue.dll mozilla::detail::InvalidArrayIndex_CRASH(unsigned long long, unsigned long long) mfbt/Assertions.cpp:50
1 xul.dll mozilla::dom::Selection::Repaint(nsPresContext*) dom/base/Selection.cpp:2370
2 xul.dll nsFrameSelection::RepaintHighlightSelection(nsAtom*) layout/generic/nsFrameSelection.cpp:1735
3 xul.dll mozilla::dom::HighlightRegistry::RepaintAllHighlightSelections() dom/base/HighlightRegistry.cpp:142
4 xul.dll mozilla::RestyleManager::DoProcessPendingRestyles(mozilla::ServoTraversalFlags) layout/style/RestyleManager.cpp:3362
5 xul.dll mozilla::PresShell::DoFlushPendingNotifications(mozilla::ChangesToFlush) layout/base/PresShell.cpp:4663
6 xul.dll mozilla::dom::Document::FlushPendingNotifications(mozilla::ChangesToFlush) dom/base/Document.cpp:12050
7 xul.dll nsIContent::GetPrimaryFrame(mozilla::FlushType) dom/base/Element.cpp:282
8 xul.dll mozilla::dom::AbstractRange::CollectClientRectsAndText(mozilla::RectCallback*, m... dom/base/AbstractRange.cpp:901
9 xul.dll mozilla::dom::AbstractRange::GetBoundingClientRect(bool, bool) dom/base/AbstractRange.cpp:962
Filed because this signature's crash volume spiked. 52 reports from 50 distinct installations on the release build of 2026-10-22 (buildid 20261022150525); the preceding 1 build-day had 3 report, and the loudest of its 4 earlier builds in the 42 days before had 3. That is 17.3x the loudest of the preceding build-days and of this signature's builds over the 42 days before (Clouseau's bar is 3x, and the Poisson excess of the day against that baseline is z = 10.8, bar 3.62). This signature is not new: its first report is in build 20260518141440 (2026-05-18), 157 days before this build.
Clouseau analysis (automated -- nothing below was checked by a human; a claim it could not ground is deliberately absent):
Selection::Repaint saves mStyledRanges.Length() in arrCount once and then loops for (i = 0; i < arrCount; i++) calling mStyledRanges.GetAbstractRangeAt(i). On a CSS Custom Highlight selection the range list gets shorter while the loop runs, so the bounds-checked nsTArray access aborts with index == length (292/292, 42/42, 167/167). The repaint is reached from a style flush inside page script (Range.getBoundingClientRect in a MutationObserver callback, via HighlightRegistry::RepaintAllHighlightSelections). The crash appeared on 2026-11-03 at once in Firefox 151, 153.x ESR, 157/158/159 release and 160 beta, on Windows, macOS and Linux, with none in the days before. That timing points to web content that started using the Highlight API this way, not to a Firefox changeset. A defensive fix is to re-check mStyledRanges.Length() on every iteration, or to loop over a strong-ref copy of the ranges. The root cause, the code path that removes highlight ranges during SelectFrames, still needs to be found.
Possible path to the crash:
Mechanism (observed): MOZ_CRASH from InvalidArrayIndex_CRASH in the inlined StyledRangeCollection::GetAbstractRangeAt(i) inside Selection::Repaint (dom/base/Selection.cpp:2370-2371 @5add844c2661). In each cluster the crash reason shows index == length, e.g. ElementAt(aIndex = 292, aLength = 292).
Path (observed from the stacks and pinned source):
- Page script calls
Range.getBoundingClientRect()in a MutationObserver microtask, which flushes style throughnsIContent::GetPrimaryFrameintoRestyleManager::DoProcessPendingRestyles. - The restyle calls
HighlightRegistry::RepaintAllHighlightSelections, thennsFrameSelection::RepaintHighlightSelection, thenSelection::Repainton a highlightSelection. RepaintsavesarrCount = mStyledRanges.Length()before the loop and never re-checks the length, callingSelectFrames(..., *mStyledRanges.GetAbstractRangeAt(i), true)on each pass.- The array ends up shorter than
arrCountwhile the loop is running, so the first index at or past the new length hits the release-mode bounds check. That is why index always equals length.
What shrinks the array (inferred, low): it is not identified. Every site that removes elements goes through StyledRangeCollection::RemoveElement*/Clear, StyledRanges::RemoveRangeAndUnregisterSelection or RemoveCollapsedRanges, or nsFrameSelection's RemoveGeneratedRanges, which is meant for normal selections only. Which of these can run inside SelectFrames for a highlight selection, or re-enter from it, is unresolved.
Trigger (inferred, medium): web content that went live around 2026-11-03 and uses CSS Custom Highlights with many ranges (dozens to hundreds) together with layout-flushing calls in MutationObserver callbacks. This rests on the crash appearing on the same day in every Firefox version and on three OSes.
Checked:
RepaintsavesarrCount = (int32_t)mStyledRanges.Length()and loopsfor (i = 0; i < arrCount; i++)callingSelectFramesonmStyledRanges.GetAbstractRangeAt(i)without re-checking the length. (dom/base/Selection.cpp@5add844c2661:2361-2379)- The saved-count loop is old: L2362 comes from bug 1633448 (2020) and L2368 from the 2018 reformat. Bug 2011011 (7b4cd69adfd7, 2026-01-21) only changed the
GetAbstractRangeAtlines 2369/2371. (mcp__history__blame dom/base/Selection.cpp 2362-2371 (release)) - All three crash clusters abort with index == length (292/292, 42/42, 167/167), which fits an array that shrank under a saved bound. (brief: MOZ_CRASH_REASON of 86435b65, 751c4fb0, 2074c5b8)
- Across all channels in the last 60 days there was 1 report on 2026-10-12 (157.0.1), then 62 on 2026-11-03 and 43 on 2026-11-04, spread over 159.0, 159.0.1, 153.6.0esr, 153.5.1, 160.0b3/b4 and 151.0. (facets field=version by_day all_channels days=60)
- Firefox 159.0 had 0 signature reports from 10-27 to 11-02 out of about 68k crash reports, then 30 on 11-03 and 26 on 11-04, so the onset follows a calendar date, not the arrival of the build. (brief: CRASH RATE BY VERSION per-day rows for 159.0)
- Over 30 days the reports are 73% Windows, 17% macOS and 10% Linux, so the crash isn't tied to one platform. (facets field=platform all_channels days=30)
- The same-day onset in builds of several ages and on several OSes points to an external trigger (web content), not a change shipped in build 20261022150525. [inferred, medium confidence] (derived from the version by_day and platform facets above)
RepaintHighlightSelectionholds a strongRefPtrto the highlightSelectionand callsRepainton it. (layout/generic/nsFrameSelection.cpp@5add844c2661:1727-1737)
Alternatives considered:
- Pushlog changesets of build 20261022150525 as the cause of the rise: disfavored -- 159.0 stayed at zero for about a week after it shipped, and the rise appeared the same day in 151, 153 ESR, 157/158 and 160 beta, which don't contain that pushlog.
- 7b4cd69adfd7 (bug 2011011), 8b688866de09 (bug 1984991) and 20e975d790c8 (bug 1872535), as named by the earlier pipeline runs: not supported -- blame shows 7b4cd69adfd7 only touched the loop body and the saved bound is from 2020; none explains the same-day onset in many versions.
- Failing hardware: disfavored -- 0% bit-flip annotations, 4% Raptor Lake, and three OSes with crash reasons that all match the same index == length pattern.
Worth checking first:
- Which code removes ranges from a highlight
SelectionwhileRepaint→SelectFramesruns (for examplensTextFrame::SelectionStateChanged, a highlight update, or a range-invalidation path)? A debug build with aMOZ_ASSERT(mStyledRanges.Length() == arrCount)after eachSelectFrames, run on the offending site, would show the mutating stack. - Which site triggers it? Crash report URLs (protected) for the 2026-11-03 cohort would identify it and give a reproduction for a test that uses many CSS highlights plus
getBoundingClientRectin a MutationObserver. - Defensive fix: loop while
i < mStyledRanges.Length(), or over a copiedAutoTArray<RefPtr<AbstractRange>>, inSelection::Repaint. Similar saved-count or index loops elsewhere in the module (for exampleSelection::Clear, which re-readsLength()) should be audited for the same invariant.
Posted automatically by Clouseau, which analyses release crashes with an LLM. Nothing above was written or checked by a human.
Comment 2•9 days ago
|
||
:dholbert, could this be triaged for investigation?
| Assignee | ||
Comment 3•9 days ago
•
|
||
Given crash volume, it looks like we should treat this as S2 at least.
I assume this isn't a recent regression, given we're seeing crash volume in versions as old as v151 (1 report) and 153esr (77 reports).
Looking at URLs and user-comments in the crash reports (for the small fraction that include that), this seems to be mostly affecting ChatGPT. I wonder if they just recently started using certain Selection/Custom-Highlight APIs (or started using them differently, such that it triggers this bug).
| Assignee | ||
Comment 4•9 days ago
•
|
||
I asked claude to come up with a testcase to trigger this crash, and here's what it came up with.
Crash report (mine, loading this testcase locally): bp-0c92df0e-019b-4177-8cb4-404920261109
| Assignee | ||
Updated•9 days ago
|
| Assignee | ||
Comment 5•8 days ago
|
||
Our call to SelectFrames can mutate mStyledRanges, including changing its
length. So, to avoid walking off the end of the array and aborting, it's safer
to iterate over a copy of the array, just as we do in
Selection::DeleteFromDocument().
Comment 7•8 days ago
|
||
| bugherder | ||
Comment 8•8 days ago
|
||
The patch landed in nightly and beta is affected, along with ESR.
:dholbert, please make an uplift decision for beta and ESR:
- For beta, nominate the patch for beta uplift approval if the fix should be included in this release, or set
status-firefox161towontfixif the fix can wait for the next release. - For ESR, nominate the patch for the appropriate ESR uplift approval if the fix should be included in ESR, or set the ESR status flag(s) to
wontfixif an uplift isn't needed. Each affected ESR release needs a decision.
Uplift requests can be submitted from Lando: D341481.
See Requesting an Uplift for documentation on how to request an uplift.
For more information, please visit BugBot documentation.
| Assignee | ||
Comment 10•8 days ago
|
||
Tracked down a regression range to inform uplift decisions.
Regression range (using attached testcase):
https://hg.mozilla.org/integration/autoland/pushloghtml?fromchange=d270382b770b3298da5b7fe796cd16982af23f74&tochange=5341f1a6efea2eaec946f3e7e3f82dd314dc0eb1
--> Regression from bug 1984991 (which makes sense since it added RepaintAllHighlightSelections, one of the functions in the backtrace).
Comment 11•8 days ago
|
||
firefox-beta Uplift Approval Request
- User impact if declined/Reason for urgency: The reason for urgency is that this is a new high-volume crash, with the volume largely coming from a prominent website, ChatGPT, which seems to have had a change that made it susceptible to trigger this crash)
- Code covered by automated testing?: yes
- Fix verified in Nightly?: yes
- Needs manual QE testing?: yes
- Steps to reproduce for manual QE testing: Load attached testcase 1, and see if it triggers the crashed-tab UI.
- Risk associated with taking this patch: low
- Explanation of risk level: It makes us snapshot an array and iterate over that snapshot, in case the original array is changed out from under us.
The snapshot has its own RefPtr references, so it will ensure that the iterated objects are kept alive, even if the original array gets modified.
- String changes made/needed?: None.
- Is Android affected?: yes
| Assignee | ||
Comment 12•8 days ago
|
||
Our call to SelectFrames can mutate mStyledRanges, including changing its
length. So, to avoid walking off the end of the array and aborting, it's safer
to iterate over a copy of the array, just as we do in
Selection::DeleteFromDocument().
Original Revision: https://phabricator.services.mozilla.com/D341481
Comment 13•8 days ago
|
||
firefox-esr153 Uplift Approval Request
- User impact if declined/Reason for urgency: The reason for urgency is that this is a new high-volume crash, with the volume largely coming from a prominent website, ChatGPT, which seems to have had a change that made it susceptible to trigger this crash)
- Code covered by automated testing?: yes
- Fix verified in Nightly?: yes
- Needs manual QE testing?: yes
- Steps to reproduce for manual QE testing: Load attached testcase 1, and see if it triggers the crashed-tab UI.
- Risk associated with taking this patch: low
- Explanation of risk level: It makes us snapshot an array and iterate over that snapshot, in case the original array is changed out from under us.
The snapshot has its own RefPtr references, so it will ensure that the iterated objects are kept alive, even if the original array gets modified.
- String changes made/needed?: None.
- Is Android affected?: yes
| Assignee | ||
Comment 14•8 days ago
|
||
Our call to SelectFrames can mutate mStyledRanges, including changing its
length. So, to avoid walking off the end of the array and aborting, it's safer
to iterate over a copy of the array, just as we do in
Selection::DeleteFromDocument().
Original Revision: https://phabricator.services.mozilla.com/D341481
Comment 15•8 days ago
|
||
firefox-release Uplift Approval Request
- User impact if declined/Reason for urgency: The reason for urgency is that this is a new high-volume crash, with the volume largely coming from a prominent website, ChatGPT, which seems to have had a change that made it susceptible to trigger this crash)
- Code covered by automated testing?: yes
- Fix verified in Nightly?: yes
- Needs manual QE testing?: yes
- Steps to reproduce for manual QE testing: Load attached testcase 1, and see if it triggers the crashed-tab UI.
- Risk associated with taking this patch: low
- Explanation of risk level: It makes us snapshot an array and iterate over that snapshot, in case the original array is changed out from under us.
The snapshot has its own RefPtr references, so it will ensure that the iterated objects are kept alive, even if the original array gets modified.
- String changes made/needed?: None
- Is Android affected?: yes
| Assignee | ||
Comment 16•8 days ago
|
||
Our call to SelectFrames can mutate mStyledRanges, including changing its
length. So, to avoid walking off the end of the array and aborting, it's safer
to iterate over a copy of the array, just as we do in
Selection::DeleteFromDocument().
Original Revision: https://phabricator.services.mozilla.com/D341481
| Assignee | ||
Comment 17•8 days ago
|
||
(In reply to Donal Meehan [:dmeehan] from comment #9)
To add to comment 8, we could take a release uplift request if it's low risk
Nominated for uplift to esr153, beta, and release. (esr115 is unaffected.)
| Assignee | ||
Updated•8 days ago
|
Updated•8 days ago
|
Updated•8 days ago
|
Comment 18•7 days ago
|
||
I was able to reproduce the crash in Win11x64 using Firefox build 150.0b1 and the test-case attached, crash contained text (Firefox 150.0b0 Crash Report [@ mozilla::detail::InvalidArrayIndex_CRASH | nsTArray_Impl<T>::ElementAt | nsTArray_Impl<T>::operator[] | mozilla::dom::StyledRangeCollection::GetAbstractRangeAt ])
Verified as fixed on Win11x64 /Mac 15 / Ubuntu24.04 using Firefox build 162.0a1, fix is not yet included in Beta. Will check in beta once available.
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/65025 for changes under testing/web-platform/tests
Upstream PR merged by moz-wptsync-bot
Updated•7 days ago
|
Updated•7 days ago
|
Comment 21•7 days ago
|
||
| uplift | ||
Updated•5 days ago
|
Updated•5 days ago
|
Comment 22•5 days ago
|
||
| uplift | ||
Updated•5 days ago
|
Updated•5 days ago
|
Comment 23•5 days ago
|
||
| uplift | ||
Comment 24•2 days ago
|
||
Verified as fixed on Win11x64 /Mac 15 using Firefox build 161.0b3.
Comment 25•2 days ago
|
||
Verified as fixed on Win11x64 /Mac 15 using Firefox build 160.0.1(20261116130455).
Comment 26•19 hours ago
|
||
Verified as fixed on Win11x64 /Mac 15 using Firefox build 153.8.0esr(20261117185949).
Description
•