Skip to content

Commit 8c41028

Browse files
committed
REGRESSION (298372@main): Occasional CheckedPtr crash when executing insertUnorderedList command
https://bugs.webkit.org/show_bug.cgi?id=299492 rdar://161086162 Reviewed by Abrar Rahman Protyasha and Ryosuke Niwa. After the changes in 298372@main, we now crash when decrementing `CheckedPtr<RenderStyle>` underneath `EditingStyle::init`: ``` if (node && node->computedStyle()) { CheckedPtr renderStyle = node->computedStyle(); removeTextFillAndStrokeColorsIfNeeded(renderStyle.get()); if (renderStyle->fontDescription().keywordSize()) { if (auto cssValue = computedStyleAtPosition.getFontSizeCSSValuePreferringKeyword()) mutableStyle->setProperty(CSSPropertyFontSize, cssValue->cssText(CSS::defaultSerializationContext())); } } ``` This is because `getFontSizeCSSValuePreferringKeyword()` updates layout, which could potentially destroy and recreate the node's renderer along with its `RenderStyle`. To fix this, we simply limit the scope of the `CheckedPtr` so that it doesn't outlive the layout update. Test: editing/execCommand/insert-unordered-list-after-DOMNodeRemoved.html * LayoutTests/editing/execCommand/insert-unordered-list-after-DOMNodeRemoved-expected.txt: Added. * LayoutTests/editing/execCommand/insert-unordered-list-after-DOMNodeRemoved.html: Added. Add a test to exercise the fix; this test passes if it does not crash. * Source/WebCore/editing/EditingStyle.cpp: (WebCore::EditingStyle::init): Canonical link: https://commits.webkit.org/300502@main
1 parent 139792a commit 8c41028

File tree

3 files changed

+65
-3
lines changed

3 files changed

+65
-3
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PASS
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<!DOCTYPE html><!-- webkit-test-runner [ dumpJSConsoleLogInStdErr=true ] -->
2+
<html>
3+
<head>
4+
<style>
5+
html, body, table, span, abbr, p, video, output {
6+
font-variant-ligatures: common-ligatures no-contextual;
7+
justify-self: unsafe self-end;
8+
-webkit-column-span: all;
9+
transform: scale3d(9, 1, 0);
10+
overflow: -webkit-paged-y clip;
11+
font-style: normal;
12+
}
13+
</style>
14+
<script>
15+
window.testRunner?.waitUntilDone();
16+
window.testRunner?.dumpAsText();
17+
resizeValue = 1
18+
insertListCount = 0
19+
20+
setTimeout(() => {
21+
document.writeln("PASS");
22+
window.testRunner?.notifyDone();
23+
}, 1000);
24+
25+
function main() {
26+
let outputElement = document.querySelector("output");
27+
let videoElement = document.querySelector("video");
28+
document.getElementById("target").addEventListener("DOMNodeRemoved", () => {
29+
try { outputElement.remove(); } catch (e) { }
30+
resizeTo(resizeValue, resizeValue++);
31+
requestAnimationFrame(() => {
32+
find("F");
33+
requestAnimationFrame(() => {
34+
document.execCommand("insertUnorderedList");
35+
});
36+
});
37+
});
38+
document.styleSheets[0].media.appendMedium("all and (orientation:portrait)");
39+
videoElement.remove();
40+
}
41+
</script>
42+
</head>
43+
<body onload="main()" contenteditable autofocus>
44+
<table rules="none" spellcheck="false" accesskey="A" border="989"></table>
45+
<span id="text">F</span>
46+
<abbr>
47+
A
48+
<p>
49+
<span id="target">
50+
<video></video>
51+
<output></output>
52+
</span>
53+
</p>
54+
</abbr>
55+
</body>
56+
</html>

Source/WebCore/editing/EditingStyle.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -590,9 +590,14 @@ void EditingStyle::init(Node* initialNode, PropertiesToInclude propertiesToInclu
590590
}
591591

592592
if (node && node->computedStyle()) {
593-
CheckedPtr renderStyle = node->computedStyle();
594-
removeTextFillAndStrokeColorsIfNeeded(renderStyle.get());
595-
if (renderStyle->fontDescription().keywordSize()) {
593+
bool shouldSetFontSize = false;
594+
{
595+
CheckedPtr renderStyle = node->computedStyle();
596+
removeTextFillAndStrokeColorsIfNeeded(renderStyle.get());
597+
shouldSetFontSize = renderStyle->fontDescription().keywordSize();
598+
}
599+
600+
if (shouldSetFontSize) {
596601
if (auto cssValue = computedStyleAtPosition.getFontSizeCSSValuePreferringKeyword())
597602
mutableStyle->setProperty(CSSPropertyFontSize, cssValue->cssText(CSS::defaultSerializationContext()));
598603
}

0 commit comments

Comments
 (0)