RESOLVED FIXED 62336
Script-created parsers should ignore data from the network
https://bugs.webkit.org/show_bug.cgi?id=62336
Summary Script-created parsers should ignore data from the network
Adam Barth
Reported 2011-06-08 15:48:17 PDT
Script-created parsers should ignore data from the network
Attachments
Patch (35.34 KB, patch)
2011-06-08 15:51 PDT, Adam Barth
no flags
work in progress (3.09 KB, patch)
2011-06-10 15:42 PDT, Adam Barth
no flags
Patch (38.37 KB, patch)
2011-06-10 15:45 PDT, Adam Barth
no flags
Patch (larger step, but cleaner) (38.09 KB, patch)
2011-06-10 16:41 PDT, Adam Barth
no flags
Adam Barth
Comment 1 2011-06-08 15:51:52 PDT
Darin Adler
Comment 2 2011-06-08 15:59:17 PDT
Comment on attachment 96499 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=96499&action=review > Source/WebCore/html/parser/HTMLDocumentParser.cpp:345 > + // If we have a script-created parser, we ignore data from the network > + // because that data belongs to the old parser. > + if (wasCreatedByScript()) > + return; Is this the right level to solve the problem at? Why does the loader try to feed in network data to the script-created parser?
Adam Barth
Comment 3 2011-06-08 16:10:00 PDT
(In reply to comment #2) > (From update of attachment 96499 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=96499&action=review > > > Source/WebCore/html/parser/HTMLDocumentParser.cpp:345 > > + // If we have a script-created parser, we ignore data from the network > > + // because that data belongs to the old parser. > > + if (wasCreatedByScript()) > > + return; > > Is this the right level to solve the problem at? I'm not entirely sure. We could solve this at the ScriptableDocumentParser level, which might be better because that's where the wasCreatedByScript bit lives. > Why does the loader try to feed in network data to the script-created parser? The loader just feeds the data to the current parser, whatever it is. In principle, you could imagine a design there the loader grabs hold of its parser at the beginning and keeps feeding data to that exact parser.
Tony Gentilcore
Comment 4 2011-06-09 02:55:31 PDT
> The loader just feeds the data to the current parser, whatever it is. In principle, you could imagine a design there the loader grabs hold of its parser at the beginning and keeps feeding data to that exact parser. I agree this sounds like a more robust approach. So the loader would just keep a reference to it, always send it data and let the isStopped() check in append() bail out if the original parser had been stopped or detached? BTW, how did you come across this issue, is there a related bug filed somewhere else?
Adam Barth
Comment 5 2011-06-09 10:34:56 PDT
There's a related issue with getting the EOF from the network, but that one is also very tricky to trigger. > BTW, how did you come across this issue, is there a related bug filed somewhere else? I found the issue while investigating a security bug.
Adam Barth
Comment 6 2011-06-10 14:03:31 PDT
> I agree this sounds like a more robust approach. Ok. I'll take that approach. I'm going to break this down into a few small patches because this stuff is delicate.
Adam Barth
Comment 7 2011-06-10 15:42:29 PDT
Created attachment 96809 [details] work in progress
Adam Barth
Comment 8 2011-06-10 15:45:41 PDT
Darin Adler
Comment 9 2011-06-10 15:55:17 PDT
Comment on attachment 96811 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=96811&action=review > Source/WebCore/loader/DocumentWriter.cpp:204 > - if (DocumentParser* parser = m_frame->document()->parser()) > - parser->appendBytes(this, str, len, flush); > + if (m_frame->document()->parser()) > + m_parser->appendBytes(this, str, len, flush); It’s not clear what the relationship between the if and the line after it is. This may need a comment. > Source/WebCore/loader/DocumentWriter.cpp:227 > - if (DocumentParser* parser = m_frame->document()->parser()) > - parser->finish(); > + if (m_frame->document()->parser()) > + m_parser->finish(); Same confusing idiom here.
Adam Barth
Comment 10 2011-06-10 16:08:27 PDT
(In reply to comment #9) > (From update of attachment 96811 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=96811&action=review > > > Source/WebCore/loader/DocumentWriter.cpp:204 > > - if (DocumentParser* parser = m_frame->document()->parser()) > > - parser->appendBytes(this, str, len, flush); > > + if (m_frame->document()->parser()) > > + m_parser->appendBytes(this, str, len, flush); > > It’s not clear what the relationship between the if and the line after it is. This may need a comment. Those branches should become more sensible in the next patch. I tried to explain that in the ChangeLog: [[ This patch is somewhat of an incremental step in that DocumentWriter still looks at document()->parser() to decide whether to call methods of m_parser. In a follow-up patch, I'll update those checks. ]] I can make the change in bigger steps that changes the branch conditions at the same time, but I figured it was better to move in small, incremental steps.
Adam Barth
Comment 11 2011-06-10 16:41:51 PDT
Created attachment 96823 [details] Patch (larger step, but cleaner)
Eric Seidel (no email)
Comment 12 2011-06-10 17:43:55 PDT
Comment on attachment 96823 [details] Patch (larger step, but cleaner) View in context: https://bugs.webkit.org/attachment.cgi?id=96823&action=review > Source/WebCore/loader/DocumentWriter.cpp:147 > + m_parser = document->parser(); Ideally we'd add a comment as to why we do this. > Source/WebCore/loader/DocumentWriter.cpp:228 > + m_parser = 0; Is this preferred over .clear()? I never remember.
WebKit Review Bot
Comment 13 2011-06-10 17:56:25 PDT
Comment on attachment 96823 [details] Patch (larger step, but cleaner) Clearing flags on attachment: 96823 Committed r88583: <http://trac.webkit.org/changeset/88583>
WebKit Review Bot
Comment 14 2011-06-10 17:56:30 PDT
All reviewed patches have been landed. Closing bug.
Adam Barth
Comment 15 2011-06-10 19:01:34 PDT
(In reply to comment #12) > (From update of attachment 96823 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=96823&action=review > > > Source/WebCore/loader/DocumentWriter.cpp:147 > > + m_parser = document->parser(); > > Ideally we'd add a comment as to why we do this. Ok. I'll try to remember to add a comment the next time I change this file. > > Source/WebCore/loader/DocumentWriter.cpp:228 > > + m_parser = 0; > > Is this preferred over .clear()? I never remember. According to Anders, yes.
Ryosuke Niwa
Comment 16 2011-06-10 23:02:31 PDT
This patch may have caused crashes on Snow Leopard Debug builds: http://build.webkit.org/results/SnowLeopard%20Intel%20Debug%20(Tests)/r88585%20(583)/results.html
Adam Barth
Comment 17 2011-06-10 23:08:45 PDT
(In reply to comment #16) > This patch may have caused crashes on Snow Leopard Debug builds: > http://build.webkit.org/results/SnowLeopard%20Intel%20Debug%20(Tests)/r88585%20(583)/results.html Thanks. I'll take a look.
Tony Gentilcore
Comment 18 2011-06-12 09:16:57 PDT
Comment on attachment 96823 [details] Patch (larger step, but cleaner) View in context: https://bugs.webkit.org/attachment.cgi?id=96823&action=review Thanks for the fix, looks good. > Source/WebCore/dom/Document.cpp:-2082 > - loader()->writer()->endIfNotLoadingMainResource(); Really nice to see this go away.
Note You need to log in before you can comment on or make changes to this bug.