From 79c7be79e347ee00240aa80edbfc165a12215a2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Wed, 7 Feb 2024 17:42:04 +0100 Subject: [PATCH] Parser: Fix the main loop getting stuck on some signatures In certain cases the parser could go back rather than forward after finding a signature, causing it to find the same signature forever until it ran out of memory. Test cases coming later in a separate patch. Bug: T356884 Change-Id: I8ac72b05e5e4ed45e6119c012a69708c9d8eda29 (cherry picked from commit 9db35873a499a756b6e94bc6dd0e1e21440606b7) --- includes/CommentParser.php | 3 ++- modules/Parser.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/includes/CommentParser.php b/includes/CommentParser.php index 4a511ec23..1b6dde777 100644 --- a/includes/CommentParser.php +++ b/includes/CommentParser.php @@ -922,7 +922,8 @@ class CommentParser { $curCommentEnd = $node; } elseif ( $node instanceof Text && ( $match = $this->findTimestamp( $node, $timestampRegexps ) ) ) { $warnings = []; - $foundSignature = $this->findSignature( $node, $lastSigNode ); + $foundSignature = $this->findSignature( $node, + $curCommentEnd === $this->rootNode ? null : $curCommentEnd ); $author = $foundSignature['username']; $lastSigNode = $foundSignature['nodes'][0]; diff --git a/modules/Parser.js b/modules/Parser.js index 7b653061e..1686f82bc 100644 --- a/modules/Parser.js +++ b/modules/Parser.js @@ -895,7 +895,8 @@ Parser.prototype.buildThreadItems = function () { curCommentEnd = node; } else if ( node.nodeType === Node.TEXT_NODE && ( match = this.findTimestamp( node, timestampRegexps ) ) ) { var warnings = []; - var foundSignature = this.findSignature( node, lastSigNode ); + var foundSignature = this.findSignature( node, + curCommentEnd === this.rootNode ? null : curCommentEnd ); var author = foundSignature.username; lastSigNode = foundSignature.nodes[ 0 ];