Bug 201769

Summary: Web Inspector: HTML Formatting: Handle infinite loop for incomplete script data
Product: WebKit Reporter: Joseph Pecoraro <joepeck>
Component: Web InspectorAssignee: Joseph Pecoraro <joepeck>
Status: RESOLVED FIXED    
Severity: Normal CC: hi, inspector-bugzilla-changes, joepeck, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: All   
OS: All   
Attachments:
Description Flags
[PATCH] Proposed Fix
none
[PATCH] Proposed Fix hi: review+

Description Joseph Pecoraro 2019-09-13 13:05:54 PDT
HTML Formatting: Handle infinite loop for incomplete script data

Steps to Reproduce:
1. Attempt to format something like "<script src="foo.js"> </sc"
  => Infinite loop
Comment 1 Joseph Pecoraro 2019-09-13 13:06:51 PDT
Created attachment 378749 [details]
[PATCH] Proposed Fix
Comment 2 Joseph Pecoraro 2019-09-13 16:35:43 PDT
Comment on attachment 378749 [details]
[PATCH] Proposed Fix

Revising this with some more edge cases.
Comment 3 Joseph Pecoraro 2019-09-13 16:42:41 PDT
Created attachment 378762 [details]
[PATCH] Proposed Fix
Comment 4 Devin Rousso 2019-09-13 18:06:47 PDT
Comment on attachment 378762 [details]
[PATCH] Proposed Fix

View in context: https://bugs.webkit.org/attachment.cgi?id=378762&action=review

r=me, looks reasonable :)

> Source/WebInspectorUI/UserInterface/Workers/Formatter/HTMLParser.js:181
> +        if (this._isEOF() && this._data.endsWith("<"))

Could you move this check into the `if (text)` above, since we would’ve consumed up to a “<“ there anyways?  I think then we could still use `_handleEOF`.

> Source/WebInspectorUI/UserInterface/Workers/Formatter/HTMLParser.js:199
> +                this._handleEOF(startPos);

Could we have `_handleEOF` return whether `_isEOF` so we don’t have to check it twice?
Comment 5 Joseph Pecoraro 2019-09-13 18:53:54 PDT
Comment on attachment 378762 [details]
[PATCH] Proposed Fix

View in context: https://bugs.webkit.org/attachment.cgi?id=378762&action=review

>> Source/WebInspectorUI/UserInterface/Workers/Formatter/HTMLParser.js:181
>> +        if (this._isEOF() && this._data.endsWith("<"))
> 
> Could you move this check into the `if (text)` above, since we would’ve consumed up to a “<“ there anyways?  I think then we could still use `_handleEOF`.

I think we will need to do both anyways. For example `<` (empty text, but last character is "<"),  and `a<` (non-empty text, but last character is "<"). Or am I overlooking something?

>> Source/WebInspectorUI/UserInterface/Workers/Formatter/HTMLParser.js:199
>> +                this._handleEOF(startPos);
> 
> Could we have `_handleEOF` return whether `_isEOF` so we don’t have to check it twice?

Sure
Comment 6 Joseph Pecoraro 2019-09-13 18:58:14 PDT
https://trac.webkit.org/r249866
Comment 7 Radar WebKit Bug Importer 2019-09-13 18:59:21 PDT
<rdar://problem/55360232>