Closed Bug 2095513 Opened 9 days ago Closed 8 days ago

[wpt-sync] Sync PR 65124 - Clone single-buffered 2D canvas in BaseRenderingContext2D::Snapshot()

Categories

(Core :: Graphics: Canvas2D, task, P4)

task

Tracking

()

RESOLVED FIXED
163 Branch
Tracking Status
firefox163 --- fixed

People

(Reporter: wpt-sync, Unassigned)

References

()

Details

(Whiteboard: [wptsync downstream])

Sync web-platform-tests PR 65124 into mozilla-central (this bug is closed when the sync is complete).

PR: https://github.com/web-platform-tests/wpt/pull/65124
Details from upstream follow.

Jean-Philippe Gravel <jpgravel@chromium.org> wrote:

Clone single-buffered 2D canvas in BaseRenderingContext2D::Snapshot()

The 2D canvas has a copy-on-write mechanism allowing the rasterized
canvas output texture to be directly given to the compositor, or to the
web page (if it does a readback) without copying it. The texture is
only copied onto a new one if the canvas continues drawing into that
same buffer while a reference is still held by readers 1.

Desynchronized canvases however are single-buffered and meant to be read
and written concurrently. The compositor will keep a reference to the
texture and copy-on-write has to be disabled for writes to happen to
that same texture 2.

This is a problem if the page takes a snapshot of the canvas because if
the texture is never copied, this gives the page direct access to the
texture being actively written by the canvas. If the page does a
readback, holds onto the image buffer and draws cross-origin data, the
cross-origin data becomes immediately visible from the buffer the page
held onto. The canvas itself becomes tainted, but the snapshot remains
origin-clean and readable by the page.

The best solution would be to implement copy-on-write for desynchronized
canvases. But, this is not easy to do because the canvas does not
currently know whether the readers holding a reference on the resource
are the compositor or the page. The copy should also work in reverse to
normal copy-on-write. Normally, we use the copy as the new canvas
backing texture used for new drawing. But for single-buffered textures,
the original texture should remain bound to the renderer and compositor,
and the copy should be given to the page (with CONCURRENT_READ_WRITE and
SCANOUT disabled).

In the context of fixing this bug with a safe and simple change, this
CL instead opts for cloning the texture early, as soon as a snapshot is
returned to the page. This ensures that cross-origin data is never
leaked.

Fixed: 566888176
Change-Id: I17424afafb949332c01a0c93819229071719e843
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8795549
Reviewed-by: Jonathan Lee \<jonathanjlee@google.com>
Commit-Queue: Jean-Philippe Gravel \<jpgravel@chromium.org>
Reviewed-by: Vasiliy Telezhnikov \<vasilyt@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1743694}

Component: web-platform-tests → Graphics: Canvas2D
Product: Testing → Core

CI Results

Ran 0 Firefox configurations based on mozilla-central, and Firefox, Chrome, and Safari on GitHub CI

Total 1 tests and 10 subtests

Status Summary

Firefox

OK : 1
PASS: 10

Chrome

OK : 1
PASS: 10

Safari

OK : 1
PASS: 10

Links

Gecko CI (Treeherder)
GitHub PR Head
GitHub PR Base

Pushed by wptsync@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/4d6d75757ad2 https://hg.mozilla.org/integration/autoland/rev/b3ced94c0010 [wpt PR 65124] - Clone single-buffered 2D canvas in BaseRenderingContext2D::Snapshot(), a=testonly
Status: NEW → RESOLVED
Closed: 8 days ago
Resolution: --- → FIXED
Target Milestone: --- → 163 Branch
You need to log in before you can comment on or make changes to this bug.