Closed Bug 2005101 Opened 11 months ago Closed 9 months ago

Land test for fixed Assertion failure: false (The container shouldn't be iterated due to out of range), at /builds/worker/checkouts/gecko/dom/base/nsRange.cpp:2113

Categories

(Core :: DOM: Selection, defect)

defect

Tracking

()

RESOLVED FIXED
149 Branch
Tracking Status
firefox-esr115 --- unaffected
firefox-esr140 --- unaffected
firefox146 --- unaffected
firefox147 --- unaffected
firefox148 --- wontfix
firefox149 --- fixed

People

(Reporter: tsmith, Assigned: masayuki)

References

(Blocks 1 open bug, Regression)

Details

(6 keywords, Whiteboard: [assertion fixed by bug 1978714][bugmon:bisected,confirmed], [wptsync upstream][adv-main149-])

Crash Data

Attachments

(1 file, 1 external file, 2 obsolete files)

Attached file testcase.html —

Found while fuzzing m-c 20251209-7c6e6dc03dc0 (--enable-debug --enable-fuzzing)

To reproduce via Grizzly Replay:

$ pip install fuzzfetch grizzly-framework --upgrade
$ python -m fuzzfetch -d --fuzzing -n firefox
$ python -m grizzly.replay.bugzilla ./firefox/firefox <bugid>

I am marking this as s-s since until this can be investigated.

Assertion failure: false (The container shouldn't be iterated due to out of range), at /builds/worker/checkouts/gecko/dom/base/nsRange.cpp:2113

#0 0x7915a7683ce8 in MOZ_CrashSequence /builds/worker/workspace/obj-build/dist/include/mozilla/Assertions.h:237:3
#1 0x7915a7683ce8 in nsRange::CutContents(mozilla::dom::DocumentFragment**, void (*)(mozilla::dom::Element*), mozilla::ErrorResult&) /builds/worker/checkouts/gecko/dom/base/nsRange.cpp:2112:11
#2 0x7915a78a64e4 in mozilla::dom::Selection::DeleteFromDocument(mozilla::ErrorResult&) /builds/worker/checkouts/gecko/dom/base/Selection.cpp:4127:27
#3 0x7915a829dba6 in mozilla::dom::Selection_Binding::deleteFromDocument(JSContext*, JS::Handle<JSObject*>, void*, JSJitMethodCallArgs const&) /builds/worker/workspace/obj-build/dom/bindings/./SelectionBinding.cpp:1653:24
#4 0x7915a8bd172d in bool mozilla::dom::binding_detail::GenericMethod<mozilla::dom::binding_detail::NormalThisPolicy, mozilla::dom::binding_detail::ThrowExceptions>(JSContext*, unsigned int, JS::Value*) /builds/worker/checkouts/gecko/dom/bindings/BindingUtils.cpp:3306:13
#5 0x7915ac647024 in CallJSNative(JSContext*, bool (*)(JSContext*, unsigned int, JS::Value*), js::CallReason, JS::CallArgs const&) /builds/worker/checkouts/gecko/js/src/vm/Interpreter.cpp:490:13
#6 0x7915ac64687f in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) /builds/worker/checkouts/gecko/js/src/vm/Interpreter.cpp:586:12
#7 0x7915ac657912 in CallFromStack /builds/worker/checkouts/gecko/js/src/vm/Interpreter.cpp:658:10
#8 0x7915ac657912 in js::Interpret(JSContext*, js::RunState&) /builds/worker/checkouts/gecko/js/src/vm/Interpreter.cpp:3272:16
#9 0x7915ac645eca in js::RunScript(JSContext*, js::RunState&) /builds/worker/checkouts/gecko/js/src/vm/Interpreter.cpp:460:13
#10 0x7915ac6468a5 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) /builds/worker/checkouts/gecko/js/src/vm/Interpreter.cpp:618:13
#11 0x7915ac647ccc in js::Call(JSContext*, JS::Handle<JS::Value>, JS::Handle<JS::Value>, js::AnyInvokeArgs const&, JS::MutableHandle<JS::Value>, js::CallReason) /builds/worker/checkouts/gecko/js/src/vm/Interpreter.cpp:685:8
#12 0x7915ac730afb in JS::Call(JSContext*, JS::Handle<JS::Value>, JS::Handle<JS::Value>, JS::HandleValueArray const&, JS::MutableHandle<JS::Value>) /builds/worker/checkouts/gecko/js/src/vm/CallAndConstruct.cpp:119:10
#13 0x7915a89922d5 in mozilla::dom::EventHandlerNonNull::Call(mozilla::dom::BindingCallContext&, JS::Handle<JS::Value>, mozilla::dom::Event&, JS::MutableHandle<JS::Value>, mozilla::ErrorResult&) /builds/worker/workspace/obj-build/dom/bindings/./EventHandlerBinding.cpp:65:37
#14 0x7915a9501feb in void mozilla::dom::EventHandlerNonNull::Call<nsCOMPtr<mozilla::dom::EventTarget>>(nsCOMPtr<mozilla::dom::EventTarget> const&, mozilla::dom::Event&, JS::MutableHandle<JS::Value>, mozilla::ErrorResult&, char const*, mozilla::dom::CallbackObjectBase::ExceptionHandling, JS::Realm*) /builds/worker/workspace/obj-build/dist/include/mozilla/dom/EventHandlerBinding.h:82:12
#15 0x7915a9500b32 in mozilla::JSEventHandler::HandleEvent(mozilla::dom::Event*) /builds/worker/checkouts/gecko/dom/events/JSEventHandler.cpp:201:12
#16 0x7915a94dbc01 in mozilla::EventListenerManager::HandleEventSingleListener(mozilla::EventListenerManager::Listener*, nsAtom*, mozilla::WidgetEvent*, mozilla::dom::Event*, mozilla::dom::EventTarget*, bool) /builds/worker/checkouts/gecko/dom/events/EventListenerManager.cpp:1273:22
#17 0x7915a94dcd59 in mozilla::EventListenerManager::HandleEventWithListenerArray(mozilla::EventListenerManager::ListenerArray*, nsAtom*, mozilla::EventMessage, nsPresContext*, mozilla::WidgetEvent*, mozilla::dom::Event**, mozilla::dom::EventTarget*, bool) /builds/worker/checkouts/gecko/dom/events/EventListenerManager.cpp:1579:12
#18 0x7915a94dc641 in mozilla::EventListenerManager::HandleEventInternal(nsPresContext*, mozilla::WidgetEvent*, mozilla::dom::Event**, mozilla::dom::EventTarget*, nsEventStatus*, bool) /builds/worker/checkouts/gecko/dom/events/EventListenerManager.cpp:1484:35
#19 0x7915a94d10de in HandleEvent /builds/worker/workspace/obj-build/dist/include/mozilla/EventListenerManager.h:465:5
#20 0x7915a94d10de in mozilla::EventTargetChainItem::HandleEvent(mozilla::EventChainPostVisitor&, mozilla::ELMCreationDetector&) /builds/worker/checkouts/gecko/dom/events/EventDispatcher.cpp:364:17
#21 0x7915a94d07ac in mozilla::EventTargetChainItem::HandleEventTargetChain(nsTArray<mozilla::EventTargetChainItem>&, mozilla::EventChainPostVisitor&, mozilla::EventDispatchingCallback*, mozilla::ELMCreationDetector&) /builds/worker/checkouts/gecko/dom/events/EventDispatcher.cpp:605:16
#22 0x7915a94d2f62 in mozilla::EventDispatcher::Dispatch(mozilla::dom::EventTarget*, nsPresContext*, mozilla::WidgetEvent*, mozilla::dom::Event*, nsEventStatus*, mozilla::EventDispatchingCallback*, nsTArray<mozilla::dom::EventTarget*>*) /builds/worker/checkouts/gecko/dom/events/EventDispatcher.cpp:1260:11
#23 0x7915ab8439aa in nsDocumentViewer::LoadComplete(nsresult) /builds/worker/checkouts/gecko/layout/base/nsDocumentViewer.cpp:994:7
#24 0x7915abcb9280 in nsDocShell::EndPageLoad(nsIWebProgress*, nsIChannel*, nsresult) /builds/worker/checkouts/gecko/docshell/base/nsDocShell.cpp:6495:13
#25 0x7915abcb873f in nsDocShell::OnStateChange(nsIWebProgress*, nsIRequest*, unsigned int, nsresult) /builds/worker/checkouts/gecko/docshell/base/nsDocShell.cpp:5816:7
#26 0x7915abcba1b2 in non-virtual thunk to nsDocShell::OnStateChange(nsIWebProgress*, nsIRequest*, unsigned int, nsresult) /builds/worker/checkouts/gecko/docshell/base/nsDocShell.cpp:0:0
#27 0x7915a65f9df9 in nsDocLoader::DoFireOnStateChange(nsIWebProgress*, nsIRequest*, int&, nsresult) /builds/worker/checkouts/gecko/uriloader/base/nsDocLoader.cpp:1528:3
#28 0x7915a65f95b2 in nsDocLoader::doStopDocumentLoad(nsIRequest*, nsresult) /builds/worker/checkouts/gecko/uriloader/base/nsDocLoader.cpp:1060:14
#29 0x7915a65f7104 in nsDocLoader::DocLoaderIsEmpty(bool, mozilla::Maybe<nsresult> const&) /builds/worker/checkouts/gecko/uriloader/base/nsDocLoader.cpp:855:9
#30 0x7915a65f895a in nsDocLoader::OnStopRequest(nsIRequest*, nsresult) /builds/worker/checkouts/gecko/uriloader/base/nsDocLoader.cpp:722:5
#31 0x7915abce028f in nsDocShell::OnStopRequest(nsIRequest*, nsresult) /builds/worker/checkouts/gecko/docshell/base/nsDocShell.cpp:14751:23
#32 0x7915a598b13f in mozilla::net::nsLoadGroup::NotifyRemovalObservers(nsIRequest*, nsresult) /builds/worker/checkouts/gecko/netwerk/base/nsLoadGroup.cpp:656:22
#33 0x7915a598c2e6 in mozilla::net::nsLoadGroup::RemoveRequest(nsIRequest*, nsISupports*, nsresult) /builds/worker/checkouts/gecko/netwerk/base/nsLoadGroup.cpp:540:10
#34 0x7915a773b6ec in mozilla::dom::Document::DoUnblockOnload() /builds/worker/checkouts/gecko/dom/base/Document.cpp:12491:18
#35 0x7915a7721726 in mozilla::dom::Document::DispatchContentLoadedEvents() /builds/worker/checkouts/gecko/dom/base/Document.cpp:8737:3
#36 0x7915a77ec4a5 in operator()<> /builds/worker/workspace/obj-build/dist/include/nsThreadUtils.h:1083:18
#37 0x7915a77ec4a5 in __invoke_impl<void, (lambda at /builds/worker/workspace/obj-build/dist/include/nsThreadUtils.h:1082:9)> /builds/worker/fetches/sysroot-x86_64-linux-gnu/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:60:14
#38 0x7915a77ec4a5 in __invoke<(lambda at /builds/worker/workspace/obj-build/dist/include/nsThreadUtils.h:1082:9)> /builds/worker/fetches/sysroot-x86_64-linux-gnu/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:95:14
#39 0x7915a77ec4a5 in __apply_impl<(lambda at /builds/worker/workspace/obj-build/dist/include/nsThreadUtils.h:1082:9), std::tuple<> &> /builds/worker/fetches/sysroot-x86_64-linux-gnu/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/tuple:1740:14
#40 0x7915a77ec4a5 in apply<(lambda at /builds/worker/workspace/obj-build/dist/include/nsThreadUtils.h:1082:9), std::tuple<> &> /builds/worker/fetches/sysroot-x86_64-linux-gnu/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/tuple:1751:14
#41 0x7915a77ec4a5 in apply<mozilla::dom::Document, void (mozilla::dom::Document::*)()> /builds/worker/workspace/obj-build/dist/include/nsThreadUtils.h:1081:12
#42 0x7915a77ec4a5 in mozilla::detail::RunnableMethodImpl<mozilla::dom::Document*, void (mozilla::dom::Document::*)(), true, (mozilla::RunnableKind)0>::Run() /builds/worker/workspace/obj-build/dist/include/nsThreadUtils.h:1132:13
#43 0x7915a5716df7 in mozilla::RunnableTask::Run() /builds/worker/checkouts/gecko/xpcom/threads/TaskController.cpp:705:16
#44 0x7915a5711774 in mozilla::TaskController::DoExecuteNextTaskOnlyMainThreadInternal(mozilla::detail::BaseAutoLock<mozilla::Mutex&> const&) /builds/worker/checkouts/gecko/xpcom/threads/TaskController.cpp:1325:20
#45 0x7915a57103f7 in mozilla::TaskController::ExecuteNextTaskOnlyMainThreadInternal(mozilla::detail::BaseAutoLock<mozilla::Mutex&> const&) /builds/worker/checkouts/gecko/xpcom/threads/TaskController.cpp:1148:15
#46 0x7915a5710875 in mozilla::TaskController::ProcessPendingMTTask(bool) /builds/worker/checkouts/gecko/xpcom/threads/TaskController.cpp:641:36
#47 0x7915a571dc76 in operator() /builds/worker/checkouts/gecko/xpcom/threads/TaskController.cpp:333:37
#48 0x7915a571dc76 in mozilla::detail::RunnableFunction<mozilla::TaskController::TaskController()::$_0>::Run() /builds/worker/checkouts/gecko/xpcom/threads/nsThreadUtils.h:549:5
#49 0x7915a572fd53 in nsThread::ProcessNextEvent(bool, bool*) /builds/worker/checkouts/gecko/xpcom/threads/nsThread.cpp:1164:16
#50 0x7915a573664f in NS_ProcessNextEvent(nsIThread*, bool) /builds/worker/checkouts/gecko/xpcom/threads/nsThreadUtils.cpp:461:10
#51 0x7915a6328767 in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) /builds/worker/checkouts/gecko/ipc/glue/MessagePump.cpp:85:21
#52 0x7915a6283c71 in RunHandler /builds/worker/checkouts/gecko/ipc/chromium/src/base/message_loop.cc:361:3
#53 0x7915a6283c71 in MessageLoop::Run() /builds/worker/checkouts/gecko/ipc/chromium/src/base/message_loop.cc:343:3
#54 0x7915ab39a6b8 in nsBaseAppShell::Run() /builds/worker/checkouts/gecko/widget/nsBaseAppShell.cpp:152:27
#55 0x7915ab4681a4 in nsAppShell::Run() /builds/worker/checkouts/gecko/widget/gtk/nsAppShell.cpp:555:33
#56 0x7915ac4aa78b in XRE_RunAppShell() /builds/worker/checkouts/gecko/toolkit/xre/nsEmbedFunctions.cpp:656:20
#57 0x7915a6329614 in mozilla::ipc::MessagePumpForChildProcess::Run(base::MessagePump::Delegate*) /builds/worker/checkouts/gecko/ipc/glue/MessagePump.cpp:235:9
#58 0x7915a6283c71 in RunHandler /builds/worker/checkouts/gecko/ipc/chromium/src/base/message_loop.cc:361:3
#59 0x7915a6283c71 in MessageLoop::Run() /builds/worker/checkouts/gecko/ipc/chromium/src/base/message_loop.cc:343:3
#60 0x7915ac4a9ee1 in XRE_InitChildProcess(int, char**, XREChildData const*) /builds/worker/checkouts/gecko/toolkit/xre/nsEmbedFunctions.cpp:594:34
#61 0x64367100cf9c in main /builds/worker/checkouts/gecko/browser/app/nsBrowserApp.cpp:465:22
Flags: in-testsuite?

Verified bug as reproducible on mozilla-central 20251210064334-deaf4cdda67a.
The bug appears to have been introduced in the following build range:

Start: c2f05ce0b22bedaac3196ad052bc7d47717e1d9c (20251209065918)
End: 4c2e2f108dd68e67c4f04a50f9e953edfb0febec (20251209072250)
Pushlog: https://hg.mozilla.org/integration/autoland/pushloghtml?fromchange=c2f05ce0b22bedaac3196ad052bc7d47717e1d9c&tochange=4c2e2f108dd68e67c4f04a50f9e953edfb0febec

Keywords: regression
Whiteboard: [bugmon:bisected,confirmed]
Flags: needinfo?(masayuki)

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

For more information, please visit BugBot documentation.

Flags: needinfo?(masayuki)
Group: dom-core-security

Interesting. It seems that the iterator lists up the anonymous <summary>.

Assignee: nobody → masayuki
Severity: -- → S3
Status: NEW → ASSIGNED
Flags: needinfo?(masayuki)
OS: Unspecified → All
Hardware: Unspecified → All

<details> has a native anonymous shadow which has 2 <slot> elements,
one is for <summary> and the other is for the content of <details>.
And the actual <summary> and the other contents of <details> are
slotted into them [1]. Therefore, GetIndexInParent<TreeKind::Flat>()
of <details> will call GetShadowRoot()->ComputeIndexOf() [2].
Then, the element is not a direct child of the shadow root so that
ComputeIndexOf() returns Nothing.

This causes RangeUtils::CompareNodeToRangeBoundaries() considering
that the node is before the range when comparing <details> and
<summary> [3].

Finally, ContentSubtreeIterator::GetTopAncestorInRange() considers
that the range starting from start of <summary> selects all of the
<summary> since it's considered by
RangeUtils::IsNodeContainedInRange() by the above bug [4]. Therefore,
the iterator lists up <summary> which is the start container as fully
selected element and the assertion fails.

This patch fixes this in
nsContentUtils::CompareChildOffsetAndChildNode() because when
comparing the parent and the child, the caller must expect that they
work so. However, within the lower level, changing the behavior may
block DOM operations with native anonymous subtrees.

  1. https://searchfox.org/firefox-main/rev/55aaa33f526ad11857e3f2e07a87daef1aa56ad4/dom/html/HTMLDetailsElement.cpp#96,107-108,132,135-136,143
  2. https://searchfox.org/firefox-main/rev/55aaa33f526ad11857e3f2e07a87daef1aa56ad4/dom/base/ChildIterator.cpp#68-69
  3. https://searchfox.org/firefox-main/rev/55aaa33f526ad11857e3f2e07a87daef1aa56ad4/dom/base/RangeUtils.cpp#290-300
  4. https://searchfox.org/firefox-main/rev/55aaa33f526ad11857e3f2e07a87daef1aa56ad4/dom/base/ContentIterator.cpp#1395-1400
Crash Signature: [@ nsRange::CutContents ]
Attachment #9532270 - Attachment description: Bug 2005101 - Make `nsContentUtils::CompareChildOffsetAndChildNode` not use `GetIndexInParent<TreeKind::Flat>()` for `<details>` r=smaug! → Bug 2005101 - Make `ContentSubtreeIterator` not use `TreeKind::Flat` version `RangeUtils` if the range's kind is not `TreeKind::Flat` r=smaug!
Attachment #9532270 - Attachment description: Bug 2005101 - Make `ContentSubtreeIterator` not use `TreeKind::Flat` version `RangeUtils` if the range's kind is not `TreeKind::Flat` r=smaug! → Bug 2005101 - Make `RangeUtils::CompareNodeToRangeBoundaries` retrieve proper parent node for comparing position r=smaug!
See Also: → 2007697
See Also: → 1982108

Testcase crashes using the initial build (mozilla-central 20251209143057-7c6e6dc03dc0) but not with tip (mozilla-central 20260130211306-fda5656fd125.)

The bug appears to have been fixed in the following build range:

Start: 5c8857fd293506b0e4cc52a5b4d4c746c3dc8815 (20260129202303)
End: f8c55b7ea4582fc9ecaab8e0ca2e0630e04a7cc0 (20260129212213)
Pushlog: https://hg.mozilla.org/integration/autoland/pushloghtml?fromchange=5c8857fd293506b0e4cc52a5b4d4c746c3dc8815&tochange=f8c55b7ea4582fc9ecaab8e0ca2e0630e04a7cc0

masayuki, can you confirm that the above bisection range is responsible for fixing this issue?
Removing bugmon keyword as no further action possible. Please review the bug and re-add the keyword for further analysis.

Flags: needinfo?(masayuki)
Keywords: bugmon

Yeah, possible fixed by it. However, we should add the testcase into the tree so that I leave this open.

Depends on: 1978714
Flags: needinfo?(masayuki)
Attachment #9532270 - Attachment is obsolete: true
Pushed by masayuki@d-toybox.com: https://github.com/mozilla-firefox/firefox/commit/fc1b8e997fdb https://hg.mozilla.org/integration/autoland/rev/1e97bc997733 Add the reported testcase and the new tested written by the obsolete patch into the tree r=jjaschke,dom-core
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/57518 for changes under testing/web-platform/tests
Whiteboard: [bugmon:bisected,confirmed] → [bugmon:bisected,confirmed], [wptsync upstream]
Status: ASSIGNED → RESOLVED
Closed: 10 months ago
Resolution: --- → FIXED
Target Milestone: --- → 149 Branch
Upstream PR merged by moz-wptsync-bot
Keywords: bugmon
Keywords: bugmon
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Group: dom-core-security
Attached file poc.html for bug 2015081 (obsolete) —

It appears that this bug can still be triggered using the attached testcase.

Attachment #9531917 - Attachment is obsolete: true

Thanks for the POC. I've not fully understand that, but looks like it's caused by unexpected mutation while the handling. That means it's a different bug even the assertion failure is at the same. So, I think it should've been handled in a new bug instead of reopening this.

Or should we put it off to run the lifecycle callbacks with a script blocker?

We should file a new bug and not re-open existing ones.

Keywords: sec-other
Summary: Assertion failure: false (The container shouldn't be iterated due to out of range), at /builds/worker/checkouts/gecko/dom/base/nsRange.cpp:2113 → Land test for fixed Assertion failure: false (The container shouldn't be iterated due to out of range), at /builds/worker/checkouts/gecko/dom/base/nsRange.cpp:2113
Whiteboard: [bugmon:bisected,confirmed], [wptsync upstream] → [assertion fixed by bug 1978714][bugmon:bisected,confirmed], [wptsync upstream]

I filed https://bugzilla.mozilla.org/show_bug.cgi?id=2015081. We can't track multiple different issues in one bug.

Status: REOPENED → RESOLVED
Closed: 10 months ago → 9 months ago
Resolution: --- → FIXED
Group: dom-core-security → core-security-release

Comment on attachment 9542889 [details]
poc.html for bug 2015081

I'll mark poc.html obsolete here to avoid confusion, and link it from the new bug.

Attachment #9542889 - Attachment description: poc.html → poc.html for bug 2015081
Attachment #9542889 - Attachment is obsolete: true
Attachment #9531917 - Attachment is obsolete: false
Flags: in-testsuite? → in-testsuite+
QA Whiteboard: [sec] [qa-triage-done-c150/b149]
Whiteboard: [assertion fixed by bug 1978714][bugmon:bisected,confirmed], [wptsync upstream] → [assertion fixed by bug 1978714][bugmon:bisected,confirmed], [wptsync upstream][adv-main149-]
Group: core-security-release
Keywords: keep-hidden
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: