Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: e0558372aafca3e5ed5bcc50d0950b60e22e281a
https://github.com/WebKit/WebKit/commit/e0558372aafca3e5ed5bcc50d0950b60e22e281a
Author: Alan Baradlay <[email protected]>
Date: 2026-09-18 (Fri, 18 Sep 2026)
Changed paths:
A LayoutTests/fast/canvas/canvas-layer-after-max-save-count-expected.txt
A LayoutTests/fast/canvas/canvas-layer-after-max-save-count.html
M Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp
Log Message:
-----------
Use-after-free in CanvasRenderingContext2DBase::beginLayer via
realizeSavesLoop early exit
https://bugs.webkit.org/show_bug.cgi?id=318378
<rdar://175228541>
Reviewed by Said Abou-Hallawa.
beginLayer() relies on realizeSaves() pushing a fresh State onto
m_stateStack so that the new layer's CanvasLayerContextSwitcher is stored
in its own frame. If the state stack is already at MaxSaveCount,
realizeSavesLoop() returns without growing the stack and
m_unrealizedSaveCount remains nonzero. Creating a layer in that case
would overwrite the targetSwitcher of the current top State, dropping the
previous layer while the new layer still holds a raw pointer to the
previous layer's GraphicsContext, leading to a use-after-free.
Fix this by returning early from beginLayer() when realizeSaves() was
unable to push a new State (m_unrealizedSaveCount is still nonzero).
Test: fast/canvas/canvas-layer-after-max-save-count.html
* LayoutTests/fast/canvas/canvas-layer-after-max-save-count-expected.txt: Added.
* LayoutTests/fast/canvas/canvas-layer-after-max-save-count.html: Added.
* Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp:
(WebCore::CanvasRenderingContext2DBase::beginLayer):
Originally-landed-as: [email protected] (c5a2b165a95e).
rdar://187507031
Canonical link: https://commits.webkit.org/321428@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications