Open Bug 2067362 Opened 3 months ago Updated 3 months ago

[macOS 27] Crash in [@ nsMenuX::MenuChildChangedVisibility]

Categories

(Core :: Widget: Cocoa, defect)

defect

Tracking

()

People

(Reporter: clouseau-bot, Unassigned)

References

(Blocks 2 open bugs)

Details

(Keywords: crash)

Crash Data

Crash report: https://crash-stats.mozilla.org/report/index/2f1c5342-1511-4e46-a45c-c79d70260828

MOZ_CRASH Reason:

MOZ_CRASH(Encountered unexpected Objective C exception)

Top 10 frames:

0  XUL  nsMenuX::MenuChildChangedVisibility(mozilla::Variant<RefPtr<nsMenuX>, RefPtr<nsM...  widget/cocoa/nsMenuX.mm:1279
1  XUL  nsMenuX::InsertMenuChild(mozilla::Variant<RefPtr<nsMenuX>, RefPtr<nsMenuItemX> >...  widget/cocoa/nsMenuX.mm:305
2  XUL  nsMenuX::ObserveContentInserted(mozilla::dom::Document*, nsIContent*, nsIContent...  widget/cocoa/nsMenuX.mm:1230
3  XUL  nsMenuGroupOwnerX::ContentInserted(nsIContent*, ContentAppendInfo const&)  widget/cocoa/nsMenuGroupOwnerX.mm:131
4  XUL  nsMenuGroupOwnerX::ContentAppended(nsIContent*, ContentAppendInfo const&)  widget/cocoa/nsMenuGroupOwnerX.mm:77
5  XUL  nsINode::ReplaceOrInsertBefore(bool, nsINode*, nsINode*, MutationEffectOnScript,...  dom/base/nsINode.cpp:3627
6  XUL  nsINode::Append(mozilla::dom::Sequence<mozilla::dom::OwningNodeOrString> const&,...  dom/base/nsINode.cpp:2796
7  XUL  mozilla::dom::Element_Binding::append(JSContext*, JS::Handle<JSObject*>, void*, ...  dom/bindings/ElementBinding.cpp:12901
8  XUL  mozilla::dom::binding_detail::GenericMethod<mozilla::dom::binding_detail::Normal...  dom/bindings/BindingUtils.cpp:3212
9  XUL  js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct,...  js/src/vm/Interpreter.cpp:622

There is 1 crash in nightly 157 with buildid 20260827182558.

This signature is not new: its first report anywhere is in build 20231211164624 (2023-12-11), 990 days before the build above. (A 364-day crash-stats search only reaches 2026-08-23, because Socorro's search index keeps about six months — which is why the signature looks much newer there.)

Clouseau analysis (automated, 72% worth investigating — a calibrated estimate that this is worth someone's time, not that the changeset below caused it). The mechanism below fits the evidence but is not proven end-to-end:

nsMenuX::MenuChildChangedVisibility deliberately MOZ_CRASHs (via NS_OBJC_END_TRY_ABORT_BLOCK) when an AppKit call like [mNativeMenu insertItem:atIndex:]/[mNativeMenu removeItem:] raises an NSException. The in-code comment on the caller nsMenuX::ObserveContentInserted documents that NSMenu has a known bug 'clobbering' items when inserted into an open menu on 'at least macOS 15 and 26', worked around by RefreshMenuChildren (bug 1710459) destroying-and-recreating every following sibling's native item on each DOM insertion. This crash is on macOS 27 — outside that tested/known-affected range — and was reached via a JS-driven batch Element.append(...), which would trigger repeated RefreshMenuChildren remove/recreate churn per inserted sibling. Given the 990-day-old signature, this is best read as an EXPOSER hypothesis: a pre-existing AppKit-exception-guarded crash whose rate/reachability may have been changed (not created) by this rework, corroborated by three hardening follow-ups landing within weeks of bug 1710459 and a related bug (2038040) that was pushed/backed-out twice in the same indexing/visibility code.

Crash OS is macOS 27, newer than the 'at least macOS 15 and 26' versions the workaround comment names as known-affected by the underlying AppKit clobbering bug; the feature pref widget.macos.native-anchored-menus this rework shipped under defaults to true in this build, so the RefreshMenuChildren code path is live.

Starting point — NOT a suspected cause: eaaa92340bd3 (gh) (bug 1710459) by :sam.

This changeset did not land in this build's pushlog window, so there is no evidence here that the crash is a recent regression from it; it is named only as the closest thing found on the crash path. If you know where this actually comes from, that correction is the most useful thing you could leave on this bug.

Code references:

What the automated skeptic pass checked (its own words — a pass means the check succeeded, which is not always support for the conclusion):

  • unverifiable refresh_menu_children_lead — Every factual element checks out (comment text, RefreshMenuChildren body, three real hardening follow-ups, a twice-reverted related bug 2038040 in the same territory, pref default true in this build) and this is a specific, non-generic clue, not window-membership — but there is no volume/version-correlated crash data or AppKit source access to prove the exception is actually caused by post-RefreshMenuChildren churn versus the pre-existing standalone AppKit quirk. Credible and worth a human's time; not provable from static reading alone.
  • pass seed_candidate_noise — 39ac2540c0ac (bug 2066407) touches only dom/bindings/BindingUtils.cpp's GlobalObject::GetAsSupports main-thread guard — zero overlap with widget/cocoa or the mutation-observer path. Correctly treated as noise, not a candidate.
  • pass mechanism — NS_OBJC_END_TRY_ABORT_BLOCK's @catch/MOZ_CRASH body confirmed by direct pinned-build source read; matches MOZ_CRASH_REASON verbatim.

:sam, can you have a look please?

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.

Flags: needinfo?(sam)
Blocks: clouseau
Blocks: macos-27
Summary: Crash in [@ nsMenuX::MenuChildChangedVisibility] → [macOS 27] Crash in [@ nsMenuX::MenuChildChangedVisibility]

Correction to the automated analysis: this seems to be a macOS 27 (Golden Gate) issue, not a regression from bug 1710459. Also, the analysed code path accounts for only 3 of the 15 crashes.

The actual exception. nsObjCExceptionLog() appends the exception to the crash report's app notes before the MOZ_CRASH, and in every one of the 7 reports I sampled it reads:

NSRangeException: *** -[__NSArrayM insertObject:atIndex:]: index 21 beyond bounds [0 .. 19]

The index is exactly two past the end in all of them. So the throwing call is [mNativeMenu insertItem:nativeItem atIndex:insertionPoint] in MenuChildChangedVisibility, and CalculateNativeInsertionPoint is overcounting by 2. It uses nativeItem.menu != nil as a proxy for "this child is currently in mNativeMenu"; on macOS 27 two preceding children pass that test while not being in the menu's item array.

Not a bug 1710459 regression. The discriminator is the macOS 27 build, not the Firefox version. Over the last 180 days:

macOS 27 build Firefox crashes this signature
<= 26A5378n ~969 0
26A5388g 390 10
26A5406e 91 3
26A5416b 65 1
26A5421a 21 1

Onset is 2026-07-25 with 26A5388g. Bug 1710459 landed 2026-02-19 and there were ~660 macOS 27 crashes between 2026-03-01 and 2026-07-23 with zero of this signature. From 07-25 onward it hits 154.0b2, 154.0b5/b8/b9/b10, 155.0b1, 156.0a1 and 157.0a1 at once, four branches, so no single changeset explains it.

The "signature is 990 days old" point is true but not relevant: the only pre-cluster reports in the index are Firefox 115 ESR on OS X 10.12/10.13, a codebase with neither RefreshMenuChildren nor native anchored menus.

Wrong code path. 12 of the 15 crashes do not go through ObserveContentInserted or RefreshMenuChildren at all. They are:

XULElement.hidden -> nsXULElement::SetHidden -> Element::UnsetAttr
  -> nsMenuGroupOwnerX::AttributeChanged
  -> nsMenuItemX::ObserveAttributeChanged -> MenuChildChangedVisibility

via nsMenuItemX.mm. That path has neither the mIsOpen guard nor the RefreshMenuChildren repair pass that ObserveContentInserted has. The Element.append path in comment 0 is the 3/15 minority.

Severity. Low volume today (macOS 27 is ~0.7% of Mac crash volume) but 12 of 15 are already beta, and this will scale with the macOS 27 rollout.

Cheapest mitigation is clamping the index to [mNativeMenu numberOfItems]; the real fix is to stop deriving it from the .menu back-pointer. Bug 2067008's nsCocoaFeatures::OnGoldenGateOrLater() is the gate if it needs to be version-conditional.

Making this block bug 2048002 and retitling with the [macOS 27] prefix used by its other dependencies.

The bug has a crash signature, thus the bug will be considered confirmed.

Status: UNCONFIRMED → NEW
Ever confirmed: true

Build 26A5388g is macOS 27 Beta 4, which was released on 2026-07-20. This is the last beta on which these crashes happen. We're now up to Beta 7, which is build 26A5421a (released 2026-08-24). I think it's likely this is an Apple bug and that Apple has fixed it. I recommend resolving this WORKSFORME.

Severity: -- → S3

Is there interest in having me pursue the mitigation mentioned in comment 1, or given the results from comment 3 are we good here?

Flags: needinfo?(sam)
You need to log in before you can comment on or make changes to this bug.