Closed Bug 1755704 Opened 3 years ago Closed 3 years ago

`OffscreenCanvas.convertToBlob` on WebGPU canvas trips TODO assert

Categories

(Core :: Graphics: WebGPU, defect)

x86_64
Linux
defect

Tracking

()

RESOLVED FIXED
101 Branch
Tracking Status
firefox101 --- verified

People

(Reporter: jkratzer, Assigned: aosmond)

References

(Blocks 2 open bugs)

Details

(Keywords: testcase, Whiteboard: [bugmon:confirm][fuzzblocker])

Attachments

(4 files)

Testcase found while fuzzing mozilla-central rev ae6487188557 (built with: --enable-debug --enable-fuzzing).

Testcase can be reproduced using the following commands:

$ pip install fuzzfetch grizzly-framework
$ python -m fuzzfetch --build ae6487188557 --debug --fuzzing -n firefox
$ python -m grizzly.replay ./firefox/firefox testcase.zip
Hit MOZ_CRASH(todo) at /dom/webgpu/CanvasContext.h:67

    =================================================================
    ==109524==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000001 (pc 0x7f56a50b8eb8 bp 0x7ffc78ddc5d0 sp 0x7ffc78ddc5d0 T0)
    ==109524==The signal is caused by a WRITE memory access.
    ==109524==Hint: address points to the zero page.
        #0 0x7f56a50b8eb8 in mozilla::webgpu::CanvasContext::GetImageBuffer(int*) /dom/webgpu/CanvasContext.h:67:5
        #1 0x7f56a4b2d177 in mozilla::dom::CanvasRenderingContextHelper::ToBlob(mozilla::dom::EncodeCompleteCallback*, nsTSubstring<char16_t>&, nsTSubstring<char16_t> const&, bool, bool, mozilla::ErrorResult&) /dom/canvas/CanvasRenderingContextHelper.cpp:111:36
        #2 0x7f56a4be2840 in mozilla::dom::OffscreenCanvas::ConvertToBlob(mozilla::dom::ImageEncodeOptions const&, mozilla::ErrorResult&) /dom/canvas/OffscreenCanvas.cpp:342:33
        #3 0x7f56a3645b5f in convertToBlob /builds/worker/workspace/obj-build/dom/bindings/OffscreenCanvasBinding.cpp:979:60
        #4 0x7f56a3645b5f in mozilla::dom::OffscreenCanvas_Binding::convertToBlob_promiseWrapper(JSContext*, JS::Handle<JSObject*>, void*, JSJitMethodCallArgs const&) /builds/worker/workspace/obj-build/dom/bindings/OffscreenCanvasBinding.cpp:993:13
        #5 0x7f56a49957ba in bool mozilla::dom::binding_detail::GenericMethod<mozilla::dom::binding_detail::NormalThisPolicy, mozilla::dom::binding_detail::ConvertExceptionsToPromises>(JSContext*, unsigned int, JS::Value*) /dom/bindings/BindingUtils.cpp:3306:13
        #6 0x7f56ac6be094 in CallJSNative /js/src/vm/Interpreter.cpp:425:13
        #7 0x7f56ac6be094 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) /js/src/vm/Interpreter.cpp:512:12
        #8 0x7f56ac6aa5ae in CallFromStack /js/src/vm/Interpreter.cpp:576:10
        #9 0x7f56ac6aa5ae in Interpret(JSContext*, js::RunState&) /js/src/vm/Interpreter.cpp:3309:16
        #10 0x7f56ac68f3b1 in js::RunScript(JSContext*, js::RunState&) /js/src/vm/Interpreter.cpp:394:13
        #11 0x7f56ac6be1cf in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) /js/src/vm/Interpreter.cpp:544:13
        #12 0x7f56ac6c031b in js::Call(JSContext*, JS::Handle<JS::Value>, JS::Handle<JS::Value>, js::AnyInvokeArgs const&, JS::MutableHandle<JS::Value>, js::CallReason) /js/src/vm/Interpreter.cpp:589:8
        #13 0x7f56ac87640d in JS::Call(JSContext*, JS::Handle<JS::Value>, JS::Handle<JS::Value>, JS::HandleValueArray const&, JS::MutableHandle<JS::Value>) /js/src/vm/CallAndConstruct.cpp:117:10
        #14 0x7f56a45c06a9 in mozilla::dom::EventListener::HandleEvent(mozilla::dom::BindingCallContext&, JS::Handle<JS::Value>, mozilla::dom::Event&, mozilla::ErrorResult&) /builds/worker/workspace/obj-build/dom/bindings/EventListenerBinding.cpp:62:8
        #15 0x7f56a528a954 in void mozilla::dom::EventListener::HandleEvent<mozilla::dom::EventTarget*>(mozilla::dom::EventTarget* const&, mozilla::dom::Event&, mozilla::ErrorResult&, char const*, mozilla::dom::CallbackObject::ExceptionHandling, JS::Realm*) /builds/worker/workspace/obj-build/dist/include/mozilla/dom/EventListenerBinding.h:65:12
        #16 0x7f56a528a410 in mozilla::EventListenerManager::HandleEventSubType(mozilla::EventListenerManager::Listener*, mozilla::dom::Event*, mozilla::dom::EventTarget*) /dom/events/EventListenerManager.cpp:1308:43
        #17 0x7f56a528babc in mozilla::EventListenerManager::HandleEventInternal(nsPresContext*, mozilla::WidgetEvent*, mozilla::dom::Event**, mozilla::dom::EventTarget*, nsEventStatus*, bool) /dom/events/EventListenerManager.cpp:1505:17
        #18 0x7f56a5279bde in mozilla::EventTargetChainItem::HandleEvent(mozilla::EventChainPostVisitor&, mozilla::ELMCreationDetector&) /dom/events/EventDispatcher.cpp:348:17
        #19 0x7f56a52783ed in mozilla::EventTargetChainItem::HandleEventTargetChain(nsTArray<mozilla::EventTargetChainItem>&, mozilla::EventChainPostVisitor&, mozilla::EventDispatchingCallback*, mozilla::ELMCreationDetector&) /dom/events/EventDispatcher.cpp:550:16
        #20 0x7f56a527c665 in mozilla::EventDispatcher::Dispatch(nsISupports*, nsPresContext*, mozilla::WidgetEvent*, mozilla::dom::Event*, nsEventStatus*, mozilla::EventDispatchingCallback*, nsTArray<mozilla::dom::EventTarget*>*) /dom/events/EventDispatcher.cpp:1085:11
        #21 0x7f56a7ce90f7 in nsDocumentViewer::LoadComplete(nsresult) /layout/base/nsDocumentViewer.cpp:1084:7
        #22 0x7f56ab74cad3 in nsDocShell::EndPageLoad(nsIWebProgress*, nsIChannel*, nsresult) /docshell/base/nsDocShell.cpp:6403:20
        #23 0x7f56ab74bdcb in nsDocShell::OnStateChange(nsIWebProgress*, nsIRequest*, unsigned int, nsresult) /docshell/base/nsDocShell.cpp:5792:7
        #24 0x7f56ab74dd9f in non-virtual thunk to nsDocShell::OnStateChange(nsIWebProgress*, nsIRequest*, unsigned int, nsresult) /docshell/base/nsDocShell.cpp
        #25 0x7f56a1848830 in nsDocLoader::DoFireOnStateChange(nsIWebProgress*, nsIRequest*, int&, nsresult) /uriloader/base/nsDocLoader.cpp:1377:3
        #26 0x7f56a1847444 in nsDocLoader::doStopDocumentLoad(nsIRequest*, nsresult) /uriloader/base/nsDocLoader.cpp:975:14
        #27 0x7f56a1843c72 in nsDocLoader::DocLoaderIsEmpty(bool, mozilla::Maybe<nsresult> const&) /uriloader/base/nsDocLoader.cpp:794:9
        #28 0x7f56a1845e35 in nsDocLoader::OnStopRequest(nsIRequest*, nsresult) /uriloader/base/nsDocLoader.cpp:677:5
        #29 0x7f56ab7869bb in nsDocShell::OnStopRequest(nsIRequest*, nsresult) /docshell/base/nsDocShell.cpp:13715:23
        #30 0x7f569f53a22e in mozilla::net::nsLoadGroup::NotifyRemovalObservers(nsIRequest*, nsresult) /netwerk/base/nsLoadGroup.cpp:614:22
        #31 0x7f569f53cc73 in mozilla::net::nsLoadGroup::RemoveRequest(nsIRequest*, nsISupports*, nsresult) /netwerk/base/nsLoadGroup.cpp:518:10
        #32 0x7f56a2aadb62 in mozilla::dom::Document::DoUnblockOnload() /dom/base/Document.cpp:11549:18
        #33 0x7f56a2a5af67 in mozilla::dom::Document::UnblockOnload(bool) /dom/base/Document.cpp:11479:9
        #34 0x7f56a2a8591c in mozilla::dom::Document::DispatchContentLoadedEvents() /dom/base/Document.cpp:7994:3
        #35 0x7f56a2b7559d in applyImpl<mozilla::dom::Document, void (mozilla::dom::Document::*)()> /builds/worker/workspace/obj-build/dist/include/nsThreadUtils.h:1147:12
        #36 0x7f56a2b7559d in apply<mozilla::dom::Document, void (mozilla::dom::Document::*)()> /builds/worker/workspace/obj-build/dist/include/nsThreadUtils.h:1153:12
        #37 0x7f56a2b7559d 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:1200:13
        #38 0x7f569f19c79f in mozilla::SchedulerGroup::Runnable::Run() /xpcom/threads/SchedulerGroup.cpp:140:20
        #39 0x7f569f1eb5d2 in mozilla::RunnableTask::Run() /xpcom/threads/TaskController.cpp:467:16
        #40 0x7f569f1afc5d in mozilla::TaskController::DoExecuteNextTaskOnlyMainThreadInternal(mozilla::detail::BaseAutoLock<mozilla::Mutex&> const&) /xpcom/threads/TaskController.cpp:770:26
        #41 0x7f569f1ad1b8 in mozilla::TaskController::ExecuteNextTaskOnlyMainThreadInternal(mozilla::detail::BaseAutoLock<mozilla::Mutex&> const&) /xpcom/threads/TaskController.cpp:606:15
        #42 0x7f569f1ad8c9 in mozilla::TaskController::ProcessPendingMTTask(bool) /xpcom/threads/TaskController.cpp:390:36
        #43 0x7f569f1f3cd1 in operator() /xpcom/threads/TaskController.cpp:124:37
        #44 0x7f569f1f3cd1 in mozilla::detail::RunnableFunction<mozilla::TaskController::InitializeInternal()::$_0>::Run() /xpcom/threads/nsThreadUtils.h:531:5
        #45 0x7f569f1d09c7 in nsThread::ProcessNextEvent(bool, bool*) /xpcom/threads/nsThread.cpp:1171:16
        #46 0x7f569f1dbf3c in NS_ProcessNextEvent(nsIThread*, bool) /xpcom/threads/nsThreadUtils.cpp:467:10
        #47 0x7f56a0702ccf in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) /ipc/glue/MessagePump.cpp:85:21
        #48 0x7f56a057b341 in RunInternal /ipc/chromium/src/base/message_loop.cc:331:10
        #49 0x7f56a057b341 in RunHandler /ipc/chromium/src/base/message_loop.cc:324:3
        #50 0x7f56a057b341 in MessageLoop::Run() /ipc/chromium/src/base/message_loop.cc:306:3
        #51 0x7f56a76846f7 in nsBaseAppShell::Run() /widget/nsBaseAppShell.cpp:137:27
        #52 0x7f56ac3da88f in XRE_RunAppShell() /toolkit/xre/nsEmbedFunctions.cpp:878:20
        #53 0x7f56a057b341 in RunInternal /ipc/chromium/src/base/message_loop.cc:331:10
        #54 0x7f56a057b341 in RunHandler /ipc/chromium/src/base/message_loop.cc:324:3
        #55 0x7f56a057b341 in MessageLoop::Run() /ipc/chromium/src/base/message_loop.cc:306:3
        #56 0x7f56ac3d9ac3 in XRE_InitChildProcess(int, char**, XREChildData const*) /toolkit/xre/nsEmbedFunctions.cpp:715:34
        #57 0x5576d2a0480d in content_process_main(mozilla::Bootstrap*, int, char**) /browser/app/../../ipc/contentproc/plugin-container.cpp:57:28
        #58 0x5576d2a04c40 in main /browser/app/nsBrowserApp.cpp:327:18
        #59 0x7f56c3c270b2 in __libc_start_main /build/glibc-eX1tMB/glibc-2.31/csu/../csu/libc-start.c:308:16
        #60 0x5576d29538d9 in _start (/home/jkratzer/builds/mc-asan/firefox+0x5d8d9)
    
    AddressSanitizer can not provide additional info.
    SUMMARY: AddressSanitizer: SEGV /dom/webgpu/CanvasContext.h:67:5 in mozilla::webgpu::CanvasContext::GetImageBuffer(int*)
    ==109524==ABORTING
Attached file testcase.zip

The severity field is not set for this bug.
:jimb, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(jimb)
Severity: -- → S3
Flags: needinfo?(jimb)

I can reproduce this on current Mozilla Central (8dff65812a56 2022-4-20) on my machine.

Okay, this is simply because mozilla::webgpu::CanvasContext has a stubbed-out implementation of nsICanvasRenderingContextInternal::GetImageBuffer.

We should do something better than crashing, but this isn't a serious bug.

Summary: Hit MOZ_CRASH(todo) at /dom/webgpu/CanvasContext.h:67 → `OffscreenCanvas.convertToBlob` on WebGPU canvas trips TODO assert

This is currently the most frequent crash hit by the dom fuzzers. Marking as fuzzblocker.

Whiteboard: [bugmon:confirm] → [bugmon:confirm][fuzzblocker]
Assignee: nobody → aosmond
Flags: needinfo?(aosmond)

Since this is a fuzzblocker, we should get it out of the fuzzers' way somehow that doesn't block on Andrew actually implementing GetImageBuffer, unless that's extremely quick.

Unless someone has a better idea, tomorrow I'll try making nsICanvasRenderingContextInternal::GetImageBuffer return an nsresult and pass back the buffer itself by reference. Then mozilla::webgpu::CanvasContext's implementation can just return NS_ERROR_NOT_IMPLEMENTED.

I can fix this today.

This reworks the CanvasManagerChild::GetSnapshot method to work with
WebGPU. This will allow it to be called for a WebGPU context from any
thread, which is useful for screenshots.

This patch hooks up the improved CanvasManagerChild::GetSnapshot method
to the WebGPU canvas context object in order to do readbacks for various
DOM facing methods such as ConvertToBlob and for Firefox Screenshots.

Flags: needinfo?(aosmond)
Status: NEW → ASSIGNED
Pushed by aosmond@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/26b11a2833b0 Part 1. Add support for reading back the front buffer for WebGPU. r=gfx-reviewers,lsalzman https://hg.mozilla.org/integration/autoland/rev/bc4e2999a2a7 Part 2. Implement stubbed out surface related WebGPU canvas methods. r=gfx-reviewers,lsalzman
Pushed by aosmond@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/39a846e43162 Part 1. Add support for reading back the front buffer for WebGPU. r=gfx-reviewers,lsalzman https://hg.mozilla.org/integration/autoland/rev/cd0b9e084bcd Part 2. Implement stubbed out surface related WebGPU canvas methods. r=gfx-reviewers,lsalzman
Status: ASSIGNED → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 101 Branch

Backed out along with Bug 1765816 for causing reftest failures on webgl-color-test.html

Status: RESOLVED → REOPENED
Flags: needinfo?(aosmond)
Resolution: FIXED → ---
Target Milestone: 101 Branch → ---
Flags: needinfo?(aosmond)
Pushed by aosmond@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/f4709e1b92b2 Part 1. Add support for reading back the front buffer for WebGPU. r=gfx-reviewers,lsalzman https://hg.mozilla.org/integration/autoland/rev/425fd869a050 Part 2. Implement stubbed out surface related WebGPU canvas methods. r=gfx-reviewers,lsalzman

My try runs suggest bug 1765816 is the cause of the failures so I landed these separately.

Flags: needinfo?(aosmond)
Status: REOPENED → RESOLVED
Closed: 3 years ago3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 101 Branch

Reproduced with nightly build from 16.02.2022.

Issue is verified fixed in 101.0 Firefox.

Flags: qe-verify+

:aosmond, since this bug contains a bisection range, could you fill (if possible) the regressed_by field?
For more information, please visit auto_nag documentation.

Flags: needinfo?(aosmond)

Sorry, wrong needinfo because of a bug in the bot.

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

Attachment

General

Created:
Updated:
Size: