Bug 266918

Summary: drawImage(detachedOffscreenCanvas) is supposed to throw
Product: WebKit Reporter: Kaiido <tristan.fraipont>
Component: CanvasAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: dino, heycam, mattwoodrow, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Safari Technology Preview   
Hardware: Unspecified   
OS: Unspecified   

Description Kaiido 2023-12-27 18:40:49 PST
When transferring an OffscreenCanvas its width and height attributes become zero. Drawing such a detached OffscreenCanvas through a 2D context's drawImage() method should thus throw a DOMException (from https://html.spec.whatwg.org/multipage/canvas.html#check-the-usability-of-the-image-argument).  

However it seems the check for the image size still uses the dimension of the OffscreenCanvas from before it got detached as can be seen in both fiddles: https://jsfiddle.net/9zvx6bok/ & https://jsfiddle.net/9zvx6bok/1/

In the first one we draw a detached OffscreenCanvas on a 2D context, where this shouldn't be possible since the reported dimensions are both zero.
In the second one, we do set the OffscreenCanvas's dimension to zero before detaching it. This one throws as expected, demonstrating that drawImage() checks the dimensions before the transfer happened.
Comment 1 Kaiido 2024-01-02 02:07:59 PST
Pull request: https://github.com/WebKit/WebKit/pull/22297
Comment 2 Radar WebKit Bug Importer 2024-01-03 18:41:13 PST
<rdar://problem/120451062>
Comment 3 EWS 2024-02-13 02:52:11 PST
Committed 274534@main (5dbd0444ac2e): <https://commits.webkit.org/274534@main>

Reviewed commits have been landed. Closing PR #22297 and removing active labels.