-
Notifications
You must be signed in to change notification settings - Fork 3.1k
HTML API: Fix possible infinite loop parsing incomplete script tags #7128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
sirreal
wants to merge
7
commits into
WordPress:trunk
from
sirreal:html-api/fix-script-tag-infinite-loop
Closed
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c98f64d
Add test case for infinite loop in skip_script_data
sirreal 8da0bd1
Fix infinite loop in skip_script_data
sirreal 8c3fe3a
Use prefix increment consistent with the rest of the method
sirreal b8f0027
Fix the infinite loop by ensuring advance is reached
sirreal 663b94a
Update tests with ticket and another case
sirreal 53b2e64
Merge branch 'trunk' into html-api/fix-script-tag-infinite-loop
dmsnell aa92098
Return early instead of breaking to the end of the function.
dmsnell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've chosen to break here because there's no way to find the script closer. The document is incomplete, so breaking and returning
false
below enters the correct code path. This could alsoreturn false
directly instead of breaking out of the loop.This condition could likely be increased. We need to match at least
<!--
so we could apply this with at least$at + 3
.I also think this could apply more aggressive length checks earlier, then skip all of the subsequent length checks. Ultimately, we need to find a script closer in order to exit
true
. It doesn't matter how much of the script contents are parsed if it can't be closed the parser will stop on incomplete input. After this line:wordpress-develop/src/wp-includes/html-api/class-wp-html-tag-processor.php
Line 1416 in a799101
We could include this to eagerly reach incomplete input if we know a closer cannot be found.
Here's my thinking:
Maybe the proposed bugfix could be landed and included in WordPress 6.6, with more optimizations included landed in another change to
trunk
.@dmsnell curious to hear your thoughts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these are valid points. what I like about advancing one character at a time is that in some cases, I leaned on that to ensure we didn't count wrong. a targeting fix sounds nice now, and then a follow-up can be tested in isolation, particularly for performance, for skipping ahead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I also like returning
false
directly - no need to further confuse control flowThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've started work on this in #9230