Closed Bug 1836824 Opened 1 year ago Closed 1 year ago

Assertion failure: watcher, at /builds/worker/workspace/obj-build/dist/include/mozilla/StateWatching.h:208

Categories

(Core :: Graphics: Canvas2D, defect, P3)

defect

Tracking

()

VERIFIED FIXED
116 Branch
Tracking Status
firefox-esr102 --- unaffected
firefox114 --- unaffected
firefox115 --- wontfix
firefox116 --- verified

People

(Reporter: tsmith, Assigned: bradwerth)

References

(Blocks 1 open bug, Regression)

Details

(Keywords: assertion, regression, testcase, Whiteboard: [bugmon:bisected,confirmed])

Attachments

(3 files, 1 obsolete file)

Attached file testcase.html (obsolete) —

Found while fuzzing m-c 20230529-c10ba3b6a8ec (--enable-debug --enable-fuzzing)

To reproduce via Grizzly Replay:

$ pip install fuzzfetch grizzly-framework
$ python -m fuzzfetch -d --fuzzing -n firefox
$ python -m grizzly.replay ./firefox/firefox testcase.html

Assertion failure: watcher, at /builds/worker/workspace/obj-build/dist/include/mozilla/StateWatching.h:208

#0 0x7f26493f5f04 in mozilla::WatchManager<mozilla::dom::RequestedFrameRefreshObserver>::Unwatch(mozilla::WatchTarget&, void (mozilla::dom::RequestedFrameRefreshObserver::*)()) /builds/worker/workspace/obj-build/dist/include/mozilla/StateWatching.h:208:5
#1 0x7f26493e7099 in mozilla::dom::RequestedFrameRefreshObserver::DetachFromRefreshDriver() /builds/worker/checkouts/gecko/dom/html/HTMLCanvasElement.cpp:283:5
#2 0x7f26493e6ff7 in mozilla::dom::HTMLCanvasElement::Destroy() /builds/worker/checkouts/gecko/dom/html/HTMLCanvasElement.cpp:489:37
#3 0x7f26493e7162 in mozilla::dom::HTMLCanvasElement::cycleCollection::Unlink(void*) /builds/worker/checkouts/gecko/dom/html/HTMLCanvasElement.cpp:498:8
#4 0x7f26456835e0 in nsCycleCollector::CollectWhite() /builds/worker/checkouts/gecko/xpcom/base/nsCycleCollector.cpp:3141:26
#5 0x7f2645684ffa in nsCycleCollector::Collect(mozilla::CCReason, ccIsManual, js::SliceBudget&, nsICycleCollectorListener*, bool) /builds/worker/checkouts/gecko/xpcom/base/nsCycleCollector.cpp:3507:26
#6 0x7f2645684ced in nsCycleCollector::ShutdownCollect() /builds/worker/checkouts/gecko/xpcom/base/nsCycleCollector.cpp:3418:20
#7 0x7f2645686106 in nsCycleCollector::Shutdown(bool) /builds/worker/checkouts/gecko/xpcom/base/nsCycleCollector.cpp:3717:5
#8 0x7f2645687b61 in nsCycleCollector_shutdown(bool) /builds/worker/checkouts/gecko/xpcom/base/nsCycleCollector.cpp:4041:18
#9 0x7f26457c9456 in mozilla::ShutdownXPCOM(nsIServiceManager*) /builds/worker/checkouts/gecko/xpcom/build/XPCOMInit.cpp:673:3
#10 0x7f264d04d35c in XRE_InitChildProcess(int, char**, XREChildData const*) /builds/worker/checkouts/gecko/toolkit/xre/nsEmbedFunctions.cpp:663:16
#11 0x55df739c9526 in content_process_main /builds/worker/checkouts/gecko/browser/app/../../ipc/contentproc/plugin-container.cpp:57:28
#12 0x55df739c9526 in main /builds/worker/checkouts/gecko/browser/app/nsBrowserApp.cpp:375:18
#13 0x7f2659429d8f in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#14 0x7f2659429e3f in __libc_start_main csu/../csu/libc-start.c:392:3
#15 0x55df739a07c8 in _start (/home/user/workspace/browsers/m-c-20230605094751-fuzzing-debug/firefox-bin+0x587c8) (BuildId: 12ad878cfaa70b2bc4a7191a0344fcaba161fd13)
Flags: in-testsuite?
Keywords: bugmon

The stack suggests this issue is more Canvas code related.

Component: DOM: Core & HTML → Graphics: Canvas2D

Hmm, is this the right testcase? I don't think the attached testcase will even create a HTMLCanvasElement.

(In reply to Timothy Nikkel (:tnikkel) from comment #2)

Hmm, is this the right testcase? I don't think the attached testcase will even create a HTMLCanvasElement.

Oh good catch, thanks.

Attached file testcase.html
Attachment #9337505 - Attachment is obsolete: true

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

Start: 531a15ae09d49e29c270830e9b873aa625a5a8c2 (20230527212147)
End: 47f0f49b40361f9c5bde3a5691dc5d65ec1e0061 (20230528204615)
Pushlog: https://hg.mozilla.org/mozilla-central/pushloghtml?fromchange=531a15ae09d49e29c270830e9b873aa625a5a8c2&tochange=47f0f49b40361f9c5bde3a5691dc5d65ec1e0061

Keywords: regression
Whiteboard: [bugmon:bisected,confirmed]

Probably bug 1834049 in that range.

Regressed by: 1834049

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

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

For more information, please visit BugBot documentation.

Flags: needinfo?(bwerth)

I will find a fix.

Assignee: nobody → bwerth
Flags: needinfo?(bwerth)
Severity: -- → S3
Priority: -- → P3

:bradwerth any updates on the investigation? Next week is the final week of Fx115 beta

Flags: needinfo?(bwerth)

This is happening because a canvas lazily-creates its context, and HTMLCanvasElement::GetFrameCaptureState has no capture state when there is no context. In this testcase, RequestedFrameRefreshObserver::Register is called when there is no context, and then Unregister is called when it does. The assertion happens because we're unwatching some state that was never watched.

Possible fixes:

  1. Eagerly create context. This is expensive and too big a change.
  2. Create the state watch when the context is created. This requires the HTMLCanvasElement to be notified when the context is created. Maybe tricky.
  3. Independently track whether or not we are watching state and only unwatch it if we watched it in the first place. This would work but it would allow HTMLCanvasElement to be in a state where it wasn't watching its owning element's capture state at all. That's would probably just hide other more serious problems.

I'll try to build a solution around idea 2, above.

Flags: needinfo?(bwerth)

Since HTMLCanvasElement has a lazily-created context, and the
RequestedFrameRefreshObserver will fail to watch the state when the
context is null, this patch adds a hook to try to re-register when
UpdateContext is called. The superclass calls UpdateContext after the
context is initially created.

Attachment #9339405 - Attachment description: Bug 1836824: Make HTMLCanvasElement re-register its frame refresh driver when a context is updated. → Bug 1836824 Part 1: Make HTMLCanvasElement re-register its frame refresh driver when a context is updated.

This changes the original fuzzer test to explicitly delete the added
canvas element, rather than trying to close the window. Confirmed that
this asserts without the changes in Part 1.

Depends on D181149

Pushed by bwerth@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/102bde84aa26
Part 1: Make HTMLCanvasElement re-register its frame refresh driver when a context is updated. r=jgilbert
https://hg.mozilla.org/integration/autoland/rev/d3ef9848c1a0
Part 2: Add a crashtest of canvas with captureStream before getContext. r=jgilbert
Status: NEW → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 116 Branch

Verified bug as fixed on rev mozilla-central 20230617092009-29e4ffb2c397.
Removing bugmon keyword as no further action possible. Please review the bug and re-add the keyword for further analysis.

Status: RESOLVED → VERIFIED
Keywords: bugmon

The patch landed in nightly and beta is affected.
:bradwerth, is this bug important enough to require an uplift?

  • If yes, please nominate the patch for beta approval.
  • If no, please set status-firefox115 to wontfix.

For more information, please visit BugBot documentation.

Flags: needinfo?(bwerth)

(In reply to BugBot [:suhaib / :marco/ :calixte] from comment #16)

The patch landed in nightly and beta is affected.
:bradwerth, is this bug important enough to require an uplift?

No need to uplift this. It only affects debug builds.

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

Attachment

General

Created:
Updated:
Size: