Title: [173028] trunk
Revision
173028
Author
[email protected]
Date
2014-08-27 15:56:06 -0700 (Wed, 27 Aug 2014)

Log Message

Drawing text in an SVG font causes load events to be fired.
<https://webkit.org/b/136269>
<rdar://problem/15724915>

Source/WebCore:

Don't flush pending load events in Document::implicitClose() for frameless documents.
This is a targeted fix for an issue where parsing SVG fonts during layout would cause
event dispatch to happen in the main document, leading to arbitrary JS execution.

Note that the testcase only works in DRT/WTR, since once the SVG font is in cached
by WebCore, we won't reparse it again. Caches are cleared between tests, so it will
correctly fail if this should regress.

Longer-term, we should clean this up and get rid of the global dispatch entirely.

Reviewed by Simon Fraser.

Test: fast/text/svg-font-trigger-load-event.html

* dom/Document.cpp:
(WebCore::Document::implicitClose):

LayoutTests:

Reviewed by Simon Fraser.

* fast/text/svg-font-trigger-load-event-expected.txt: Added.
* fast/text/svg-font-trigger-load-event.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (173027 => 173028)


--- trunk/LayoutTests/ChangeLog	2014-08-27 22:35:18 UTC (rev 173027)
+++ trunk/LayoutTests/ChangeLog	2014-08-27 22:56:06 UTC (rev 173028)
@@ -1,3 +1,14 @@
+2014-08-27  Andreas Kling  <[email protected]>
+
+        Drawing text in an SVG font causes load events to be fired.
+        <https://webkit.org/b/136269>
+        <rdar://problem/15724915>
+
+        Reviewed by Simon Fraser.
+
+        * fast/text/svg-font-trigger-load-event-expected.txt: Added.
+        * fast/text/svg-font-trigger-load-event.html: Added.
+
 2014-08-27  Benjamin Poulain  <[email protected]>
 
         Updating attributes on HTML elements do not invalidate the style correctly unless the attribute name is lowercase in the stylesheet

Added: trunk/LayoutTests/fast/text/svg-font-trigger-load-event-expected.txt (0 => 173028)


--- trunk/LayoutTests/fast/text/svg-font-trigger-load-event-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/text/svg-font-trigger-load-event-expected.txt	2014-08-27 22:56:06 UTC (rev 173028)
@@ -0,0 +1,5 @@
+This test makes sure that drawing text in an SVG font that resides in another document doesn't cause load events to be fired. The test is successful if the image load hander line blow occurs after the line that says it should be before the image load handler.
+This line should occur before the image load handler.
+Image load handler occurred.
+
+This is some dummy text

Added: trunk/LayoutTests/fast/text/svg-font-trigger-load-event.html (0 => 173028)


--- trunk/LayoutTests/fast/text/svg-font-trigger-load-event.html	                        (rev 0)
+++ trunk/LayoutTests/fast/text/svg-font-trigger-load-event.html	2014-08-27 22:56:06 UTC (rev 173028)
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+@font-face {
+    font-family: 'SVGraffiti';
+    src: url("../../svg/custom/resources/graffiti.svg") format(svg)
+}
+</style>
+</head>
+<body>
+This test makes sure that drawing text in an SVG font that resides in another document doesn't cause load events to be fired. The test is successful if the image load hander line blow occurs after the line that says it should be before the image load handler.
+<pre id="log"></pre>
+<script>
+function log(line) {
+    document.querySelector("#log").innerText += line + '\n';
+}
+function imageLoadHandler() {
+    log("Image load handler occurred.");
+}
+if (window.testRunner)
+    testRunner.dumpAsText();
+</script>
+<img src="" _onload_="imageLoadHandler();">
+<div style="font-family: SVGraffiti;">This is some dummy text</div>
+<script>
+log("This line should occur before the image load handler.");
+</script>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (173027 => 173028)


--- trunk/Source/WebCore/ChangeLog	2014-08-27 22:35:18 UTC (rev 173027)
+++ trunk/Source/WebCore/ChangeLog	2014-08-27 22:56:06 UTC (rev 173028)
@@ -1,3 +1,26 @@
+2014-08-27  Andreas Kling  <[email protected]>
+
+        Drawing text in an SVG font causes load events to be fired.
+        <https://webkit.org/b/136269>
+        <rdar://problem/15724915>
+
+        Don't flush pending load events in Document::implicitClose() for frameless documents.
+        This is a targeted fix for an issue where parsing SVG fonts during layout would cause
+        event dispatch to happen in the main document, leading to arbitrary JS execution.
+
+        Note that the testcase only works in DRT/WTR, since once the SVG font is in cached
+        by WebCore, we won't reparse it again. Caches are cleared between tests, so it will
+        correctly fail if this should regress.
+
+        Longer-term, we should clean this up and get rid of the global dispatch entirely.
+
+        Reviewed by Simon Fraser.
+
+        Test: fast/text/svg-font-trigger-load-event.html
+
+        * dom/Document.cpp:
+        (WebCore::Document::implicitClose):
+
 2014-08-27  Simon Fraser  <[email protected]>
 
         Some EventHandler naming cleanup

Modified: trunk/Source/WebCore/dom/Document.cpp (173027 => 173028)


--- trunk/Source/WebCore/dom/Document.cpp	2014-08-27 22:35:18 UTC (rev 173027)
+++ trunk/Source/WebCore/dom/Document.cpp	2014-08-27 22:56:06 UTC (rev 173028)
@@ -2380,15 +2380,17 @@
     if (f) {
         f->loader().icon().startLoader();
         f->animation().startAnimationsIfNotSuspended(this);
+
+        // FIXME: We shouldn't be dispatching pending events globally on all Documents here.
+        // For now, only do this when there is a Frame, otherwise this could cause JS reentrancy
+        // below SVG font parsing, for example. <https://webkit.org/b/136269>
+        ImageLoader::dispatchPendingBeforeLoadEvents();
+        ImageLoader::dispatchPendingLoadEvents();
+        ImageLoader::dispatchPendingErrorEvents();
+        HTMLLinkElement::dispatchPendingLoadEvents();
+        HTMLStyleElement::dispatchPendingLoadEvents();
     }
 
-    ImageLoader::dispatchPendingBeforeLoadEvents();
-    ImageLoader::dispatchPendingLoadEvents();
-    ImageLoader::dispatchPendingErrorEvents();
-
-    HTMLLinkElement::dispatchPendingLoadEvents();
-    HTMLStyleElement::dispatchPendingLoadEvents();
-
     // To align the HTML load event and the SVGLoad event for the outermost <svg> element, fire it from
     // here, instead of doing it from SVGElement::finishedParsingChildren (if externalResourcesRequired="false",
     // which is the default, for ='' its fired at a later time, once all external resources finished loading).
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to