Title: [151611] trunk
Revision
151611
Author
[email protected]
Date
2013-06-14 16:05:39 -0700 (Fri, 14 Jun 2013)

Log Message

Threaded HTML parser can ASSERT in some situations
https://bugs.webkit.org/show_bug.cgi?id=117662

Reviewed by Ryosuke Niwa.

Source/WebCore:

This patch merges https://chromium.googlesource.com/chromium/blink/+/3c0a112b42d72c7623f78463166dd7f04d680b4c

--->8---
The parser is supposed to stop processing data when there's a pending
location change, but before this CL we would actually process the first
token from every chunk when there was a pending location change.

If the first token in a chunk was a "script" start tag, that would put
the tree builder into TextMode, which can only process character
tokens. If the next chunk starts with another start tag token, the tree
builder would be sad and hit an ASSERT.

This CL reorders a couple lines in HTMLDocumentParser so that we check
for pending location changes before processing any tokens. This change
stops us from processing the first token from each chunk while there is
a pending location change.

This issue can reproduce on any platform, but it reproduced often on
Android because mobile markup often elides spaces between consecutive
script tags. If there are space characters between the script tags,
then those space characters will be the first ones processes in the
chunk, which doesn't trigger the ASSERT.
---8<---

Since we landed this patch in Blink, we've been able to reproduce this
issue on desktops as well. I spoke with rniwa in #webkit and he said
that WebKit doesn't have any current plans to enable the threaded
parser but that it was probably worth merging this patch anyway.

Test: http/tests/navigation/pending-location-change-assert.html

* html/parser/HTMLDocumentParser.cpp:
(WebCore::HTMLDocumentParser::processParsedChunkFromBackgroundParser):

LayoutTests:

* http/tests/navigation/pending-location-change-assert-expected.txt: Added.
* http/tests/navigation/pending-location-change-assert.html: Added.
* http/tests/resources/slow-notify-done.php: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (151610 => 151611)


--- trunk/LayoutTests/ChangeLog	2013-06-14 22:49:14 UTC (rev 151610)
+++ trunk/LayoutTests/ChangeLog	2013-06-14 23:05:39 UTC (rev 151611)
@@ -1,3 +1,14 @@
+2013-06-14  Adam Barth  <[email protected]>
+
+        Threaded HTML parser can ASSERT in some situations
+        https://bugs.webkit.org/show_bug.cgi?id=117662
+
+        Reviewed by Ryosuke Niwa.
+
+        * http/tests/navigation/pending-location-change-assert-expected.txt: Added.
+        * http/tests/navigation/pending-location-change-assert.html: Added.
+        * http/tests/resources/slow-notify-done.php: Added.
+
 2013-06-14  Arpita Bahuguna  <[email protected]>
 
         Editing: wrong text position when you click enter on the text behind the image

Added: trunk/LayoutTests/http/tests/navigation/pending-location-change-assert-expected.txt (0 => 151611)


--- trunk/LayoutTests/http/tests/navigation/pending-location-change-assert-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/navigation/pending-location-change-assert-expected.txt	2013-06-14 23:05:39 UTC (rev 151611)
@@ -0,0 +1 @@
+DONE!

Added: trunk/LayoutTests/http/tests/navigation/pending-location-change-assert.html (0 => 151611)


--- trunk/LayoutTests/http/tests/navigation/pending-location-change-assert.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/navigation/pending-location-change-assert.html	2013-06-14 23:05:39 UTC (rev 151611)
@@ -0,0 +1,13 @@
+<script>
+if (window.testRunner) {
+    testRunner.dumpAsText();
+    testRunner.waitUntilDone();
+}
+window.location = "../resources/slow-notify-done.php";
+</script><script>
+alert('FAIL 1 of 3');
+</script><script>
+alert('FAIL 2 of 3');
+</script><script>
+alert('FAIL 3 of 3');
+</script>

Added: trunk/LayoutTests/http/tests/resources/slow-notify-done.php (0 => 151611)


--- trunk/LayoutTests/http/tests/resources/slow-notify-done.php	                        (rev 0)
+++ trunk/LayoutTests/http/tests/resources/slow-notify-done.php	2013-06-14 23:05:39 UTC (rev 151611)
@@ -0,0 +1,8 @@
+<?php
+usleep(100000);
+?>
+DONE!
+<script>
+if (window.testRunner)
+    testRunner.notifyDone();
+</script>

Modified: trunk/Source/WebCore/ChangeLog (151610 => 151611)


--- trunk/Source/WebCore/ChangeLog	2013-06-14 22:49:14 UTC (rev 151610)
+++ trunk/Source/WebCore/ChangeLog	2013-06-14 23:05:39 UTC (rev 151611)
@@ -1,3 +1,44 @@
+2013-06-14  Adam Barth  <[email protected]>
+
+        Threaded HTML parser can ASSERT in some situations
+        https://bugs.webkit.org/show_bug.cgi?id=117662
+
+        Reviewed by Ryosuke Niwa.
+
+        This patch merges https://chromium.googlesource.com/chromium/blink/+/3c0a112b42d72c7623f78463166dd7f04d680b4c
+
+        --->8---
+        The parser is supposed to stop processing data when there's a pending
+        location change, but before this CL we would actually process the first
+        token from every chunk when there was a pending location change.
+
+        If the first token in a chunk was a "script" start tag, that would put
+        the tree builder into TextMode, which can only process character
+        tokens. If the next chunk starts with another start tag token, the tree
+        builder would be sad and hit an ASSERT.
+
+        This CL reorders a couple lines in HTMLDocumentParser so that we check
+        for pending location changes before processing any tokens. This change
+        stops us from processing the first token from each chunk while there is
+        a pending location change.
+
+        This issue can reproduce on any platform, but it reproduced often on
+        Android because mobile markup often elides spaces between consecutive
+        script tags. If there are space characters between the script tags,
+        then those space characters will be the first ones processes in the
+        chunk, which doesn't trigger the ASSERT.
+        ---8<---
+
+        Since we landed this patch in Blink, we've been able to reproduce this
+        issue on desktops as well. I spoke with rniwa in #webkit and he said
+        that WebKit doesn't have any current plans to enable the threaded
+        parser but that it was probably worth merging this patch anyway.
+
+        Test: http/tests/navigation/pending-location-change-assert.html
+
+        * html/parser/HTMLDocumentParser.cpp:
+        (WebCore::HTMLDocumentParser::processParsedChunkFromBackgroundParser):
+
 2013-06-14  Patrick Gansterer  <[email protected]>
 
         Introduce USE(WINGDI) for the Windows port

Modified: trunk/Source/WebCore/html/parser/HTMLDocumentParser.cpp (151610 => 151611)


--- trunk/Source/WebCore/html/parser/HTMLDocumentParser.cpp	2013-06-14 22:49:14 UTC (rev 151610)
+++ trunk/Source/WebCore/html/parser/HTMLDocumentParser.cpp	2013-06-14 23:05:39 UTC (rev 151611)
@@ -414,13 +414,6 @@
     for (Vector<CompactHTMLToken>::const_iterator it = tokens->begin(); it != tokens->end(); ++it) {
         ASSERT(!isWaitingForScripts());
 
-        m_textPosition = it->textPosition();
-
-        constructTreeFromCompactHTMLToken(*it);
-
-        if (isStopped())
-            break;
-
         if (!isParsingFragment()
             && document()->frame() && document()->frame()->navigationScheduler()->locationChangePending()) {
 
@@ -433,6 +426,13 @@
             break;
         }
 
+        m_textPosition = it->textPosition();
+
+        constructTreeFromCompactHTMLToken(*it);
+
+        if (isStopped())
+            break;
+
         if (isWaitingForScripts()) {
             ASSERT(it + 1 == tokens->end()); // The </script> is assumed to be the last token of this bunch.
             runScriptsForPausedTreeBuilder();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to