From 1270194d4d6729088a7180b0fd64370a94b9f24a Mon Sep 17 00:00:00 2001 From: Dennis Snell Date: Wed, 20 Dec 2023 10:53:47 -0600 Subject: [PATCH] Fix bug found from HTML5Tests for incomplete SCRIPT tag closer --- src/wp-includes/html-api/class-wp-html-tag-processor.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/html-api/class-wp-html-tag-processor.php b/src/wp-includes/html-api/class-wp-html-tag-processor.php index f55054b957747..7b17276f92873 100644 --- a/src/wp-includes/html-api/class-wp-html-tag-processor.php +++ b/src/wp-includes/html-api/class-wp-html-tag-processor.php @@ -1267,6 +1267,12 @@ private function skip_script_data() { continue; } + if ( $this->bytes_already_parsed >= $doc_length ) { + $this->parser_state = self::STATE_INCOMPLETE; + + return false; + } + if ( '>' === $html[ $this->bytes_already_parsed ] ) { $this->bytes_already_parsed = $closer_potentially_starts_at; return true; @@ -1362,7 +1368,7 @@ private function parse_next_tag() { * https://html.spec.whatwg.org/multipage/parsing.html#tag-open-state */ if ( - strlen( $html ) > $at + 3 && + $doc_length > $at + 3 && '-' === $html[ $at + 2 ] && '-' === $html[ $at + 3 ] ) {