Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Don't GC img elements blocked by CSP until error events fire.
https://bugs.webkit.org/show_bug.cgi?id=94677 Patch by Mike West <mkwst@chromium.org> on 2012-09-17 Reviewed by Jochen Eisinger. Source/WebCore: Currently, the GC checks that no load events are pending for an image element before reclaiming its memory. It's not, however, checking that error events are taken care of. This leads to the potential of firing an event on a DOM element that we've already collected. That's a Bad Thing. This patch adjusts the check to catch error events as well as load events, which should ensure that the element isn't collected until it's really ready. As a drive-by, it also changes the name of the check to 'hasPendingActivity' from 'hasPendingLoadEvent' for clarity. http/tests/security/contentSecurityPolicy/register-bypassing-scheme.html should no longer crash, and the new http/tests/security/contentSecurityPolicy/img-blocked-no-gc-crash.html and fast/events/onerror-img-after-gc.html shouldn't crash either. Tests: fast/events/onerror-img-after-gc.html http/tests/security/contentSecurityPolicy/img-blocked-no-gc-crash.html * bindings/v8/V8GCController.cpp: (WebCore::calculateGroupId): Switch to using ImageLoader::hasPendingActivity(). * html/HTMLImageElement.h: (WebCore::HTMLImageElement::hasPendingActivity): Switch to using ImageLoader::hasPendingActivity(). * loader/ImageLoader.h: (WebCore::ImageLoader::hasPendingActivity): Added a check against pending error events in order to ensure that elements aren't garbage collected prematurely. Aslo renamed from ImageLoader::hasPendingLoadEvent for clarity. * svg/SVGImageElement.cpp: (WebCore::SVGImageElement::haveLoadedRequiredResources): Switch to using ImageLoader::hasPendingActivity(). LayoutTests: * fast/events/onerror-img-after-gc.html: * fast/events/onerror-img-after-gc-expected.txt: * http/tests/security/contentSecurityPolicy/img-blocked-no-gc-crash.html: * http/tests/security/contentSecurityPolicy/img-blocked-no-gc-crash-expected.txt: Explicitly triggering GC before the error in the hopes of proving that we don't crash anymore. * platform/gtk/TestExpectations: * platform/qt/Skipped: Unskipping no-longer-crashing test. Canonical link: https://commits.webkit.org/114812@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@128730 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
1 parent
cd22a9d
commit 5c812eda560c70e0c4d91f9adc3c0c4bac41a2c1
Showing
12 changed files
with
144 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
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
@@ -0,0 +1,2 @@ | ||
ALERT: PASS (1/1) | ||
This test ensures that a normal image error doesn't crash if GC occurs before the error event fires. |
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
@@ -0,0 +1,38 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script src="../js/resources/js-test-pre.js"></script> | ||
<script> | ||
if (window.testRunner) | ||
testRunner.waitUntilDone(); | ||
|
||
function test() { | ||
(function () { | ||
var img = document.createElement('img'); | ||
img.onload = function () { | ||
alert('FAIL (1/1)'); | ||
finishTesting(); | ||
}; | ||
img.onerror = function () { | ||
alert('PASS (1/1)'); | ||
finishTesting(); | ||
}; | ||
img.src = "foo"; | ||
})(); | ||
gc(); | ||
} | ||
|
||
function finishTesting() { | ||
if (window.testRunner) | ||
setTimeout(function () { testRunner.notifyDone(); }, 0); | ||
return true; | ||
} | ||
</script> | ||
</head> | ||
<body onload='test();'> | ||
<p> | ||
This test ensures that a normal image error doesn't crash if GC occurs | ||
before the error event fires. | ||
</p> | ||
</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
@@ -0,0 +1,4 @@ | ||
CONSOLE MESSAGE: Refused to load the image 'http://127.0.0.1:8000/security/resources/abe.png' because it violates the following Content Security Policy directive: "img-src 'none'". | ||
|
||
ALERT: PASS (1/1) | ||
This test ensures that blocking an image via CSP doesn't crash if GC executes before the error event fires. |
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
@@ -0,0 +1,39 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script src="/resources/js-test-pre.js"></script> | ||
<meta http-equiv="X-WebKit-CSP" content="img-src 'none'; script-src 'unsafe-inline'"> | ||
<script> | ||
if (window.testRunner) | ||
testRunner.waitUntilDone(); | ||
|
||
function test() { | ||
(function () { | ||
var img = document.createElement('img'); | ||
img.onload = function () { | ||
alert('FAIL (1/1)'); | ||
finishTesting(); | ||
}; | ||
img.onerror = function () { | ||
alert('PASS (1/1)'); | ||
finishTesting(); | ||
}; | ||
img.src = "../resources/abe.png"; | ||
})(); | ||
gc(); | ||
} | ||
|
||
function finishTesting() { | ||
if (window.testRunner) | ||
setTimeout(function () { testRunner.notifyDone(); }, 0); | ||
return true; | ||
} | ||
</script> | ||
</head> | ||
<body onload='test();'> | ||
<p> | ||
This test ensures that blocking an image via CSP doesn't crash if GC | ||
executes before the error event fires. | ||
</p> | ||
</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
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
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