Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge r165821 - Mutating rules returned by getMatchedCSSRules can res…
…ult in crash https://bugs.webkit.org/show_bug.cgi?id=130209 Source/WebCore: Reviewed by Andreas Kling. The non-standard getMatchedCSSRules API returns CSSStyleRule objects that don't have parent stylesheet pointer (as we don't know which sheet the rule originated from). Mutating the rule via such wrapper can lead to crashes later as we fail to invalidate the underlying stylesheet. Fix by disallowing mutation of style rules that don't have parent sheet pointer. CSSStyleRule has two mutable properties selectorText and style. The latter gives back CSSStyleDeclaration. This patch disallows mutations in both cases for CSSStyleRules that don't have parent stylesheet pointer. While it is technically possible to have CSSRules that are legitimately disconnected from stylesheet (by removing rule from sheet while holding a reference to it) it never makes sense to mutate such rule as there is no way to do anything with it afterwards. Tests: fast/css/getMatchedCSSProperties-rule-mutation.html fast/css/getMatchedCSSRules-crash.html * css/CSSStyleRule.cpp: (WebCore::CSSStyleRule::setSelectorText): Bail out if parent stylesheet is null. * css/PropertySetCSSStyleDeclaration.cpp: (WebCore::PropertySetCSSStyleDeclaration::setCssText): (WebCore::PropertySetCSSStyleDeclaration::setProperty): (WebCore::PropertySetCSSStyleDeclaration::removeProperty): (WebCore::PropertySetCSSStyleDeclaration::setPropertyInternal): Allow StyleRuleCSSStyleDeclaration subclass cancel the mutation via boolean return value from willMutate. (WebCore::StyleRuleCSSStyleDeclaration::willMutate): Disallow mutation if the owning CSSStyleRule is null or has null stylesheet. (WebCore::StyleRuleCSSStyleDeclaration::didMutate): We never get here with null rule or stylesheet anymore. * css/PropertySetCSSStyleDeclaration.h: (WebCore::PropertySetCSSStyleDeclaration::willMutate): LayoutTests: Reviewed by Andreas Kling. * fast/css/getMatchedCSSProperties-rule-mutation-expected.txt: Added. * fast/css/getMatchedCSSProperties-rule-mutation.html: Added. * fast/css/getMatchedCSSRules-crash-expected.txt: Added. * fast/css/getMatchedCSSRules-crash.html: Added.
- Loading branch information
1 parent
1e9d57f
commit 6e4f449
Showing
9 changed files
with
192 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
LayoutTests/fast/css/getMatchedCSSProperties-rule-mutation-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Test that CSSStyleRules returned by getMatchedCSSRules can't be mutated | ||
|
||
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". | ||
|
||
|
||
PASS rules.length is 2 | ||
PASS rules[0].selectorText is originalText | ||
PASS rules[1].selectorText is originalText | ||
PASS rules[0].style.cssText is originalText | ||
PASS rules[1].style.cssText is originalText | ||
PASS rules[0].style.color is originalText | ||
PASS rules[1].style.color is originalText | ||
PASS rules[0].style.getPropertyValue('color') is originalText | ||
PASS rules[1].style.getPropertyValue('color') is originalText | ||
PASS rules[0].style.color is originalText | ||
PASS rules[1].style.color is originalText | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
67 changes: 67 additions & 0 deletions
67
LayoutTests/fast/css/getMatchedCSSProperties-rule-mutation.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script src="../../resources/js-test-pre.js"></script> | ||
<style> | ||
#test { color: blue; } | ||
@media all { | ||
#test { color: blue; } | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id=test> | ||
</div> | ||
<script> | ||
|
||
description("Test that CSSStyleRules returned by getMatchedCSSRules can't be mutated"); | ||
|
||
var testDiv = document.getElementById('test'); | ||
var rules = getMatchedCSSRules(testDiv); | ||
|
||
function tryMutateSelector(index) { | ||
originalText = rules[index].selectorText; | ||
rules[index].selectorText = "#mutated"; | ||
shouldBe("rules["+index+"].selectorText", "originalText"); | ||
} | ||
|
||
function tryMutateCSSText(index) { | ||
originalText = rules[index].style.cssText; | ||
rules[index].style.cssText = "color: red"; | ||
shouldBe("rules["+index+"].style.cssText", "originalText"); | ||
} | ||
|
||
function tryMutateProperty(index) { | ||
originalText = rules[index].style.color; | ||
rules[index].style.color = "green"; | ||
shouldBe("rules["+index+"].style.color", "originalText"); | ||
} | ||
|
||
function tryMutateProperty2(index) { | ||
originalText = rules[index].style.getPropertyValue("color"); | ||
rules[index].style.setProperty("color", "white"); | ||
shouldBe("rules["+index+"].style.getPropertyValue('color')", "originalText"); | ||
} | ||
|
||
function tryRemoveProperty(index) { | ||
originalText = rules[index].style.color; | ||
rules[index].style.removeProperty("color"); | ||
shouldBe("rules["+index+"].style.color", "originalText"); | ||
} | ||
|
||
shouldBe("rules.length", "2"); | ||
tryMutateSelector(0); | ||
tryMutateSelector(1); | ||
tryMutateCSSText(0); | ||
tryMutateCSSText(1); | ||
tryMutateProperty(0); | ||
tryMutateProperty(1); | ||
tryMutateProperty2(0); | ||
tryMutateProperty2(1); | ||
tryRemoveProperty(0); | ||
tryRemoveProperty(1); | ||
|
||
</script> | ||
<script src="../../resources/js-test-post.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This test passes if it doesn't crash. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<html> | ||
<script> | ||
if (window.testRunner) | ||
testRunner.dumpAsText(); | ||
</script> | ||
<style>html,tr,img, table,media,body, li, em:nth-child(5){ | ||
height: 500px | ||
} | ||
</style> | ||
<script> | ||
function load() { | ||
var cssRules = window.getMatchedCSSRules(document.documentElement); | ||
cssRules[0].selectorText = 'a,td'; | ||
} | ||
</script> | ||
This test passes if it doesn't crash. | ||
<iframe onload=load()> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters