Skip to content

Commit e7584cf

Browse files
committed
Fix catastrophic backtracking when parsing link labels/titles
1 parent 71f63e9 commit e7584cf

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ Updates should follow the [Keep a CHANGELOG](https://keepachangelog.com/) princi
105105
- Fixed quadratic complexity finding the bottom opener for emphasis and strikethrough delimiters
106106
- Fixed issue where having 500,000+ delimiters could trigger a [known segmentation fault issue in PHP's garbage collection](https://bugs.php.net/bug.php?id=68606)
107107
- Fixed quadratic complexity deactivating link openers
108+
- Fixed catastrophic backtracking when parsing link labels/titles
108109

109110
## [2.4.1] - 2023-08-30
110111

src/Util/LinkParserHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static function parseLinkLabel(Cursor $cursor): int
6969

7070
public static function parsePartialLinkLabel(Cursor $cursor): ?string
7171
{
72-
return $cursor->match('/^(?:[^\\\\\[\]]+|\\\\.?)*/');
72+
return $cursor->match('/^(?:[^\\\\\[\]]++|\\\\.?)*+/');
7373
}
7474

7575
/**

src/Util/RegexHelper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ final class RegexHelper
6161
self::PARTIAL_PROCESSINGINSTRUCTION . '|' . self::PARTIAL_DECLARATION . '|' . self::PARTIAL_CDATA . ')';
6262
public const PARTIAL_HTMLBLOCKOPEN = '<(?:' . self::PARTIAL_BLOCKTAGNAME . '(?:[\s\/>]|$)' . '|' .
6363
'\/' . self::PARTIAL_BLOCKTAGNAME . '(?:[\s>]|$)' . '|' . '[?!])';
64-
public const PARTIAL_LINK_TITLE = '^(?:"(' . self::PARTIAL_ESCAPED_CHAR . '|[^"\x00])*"' .
65-
'|' . '\'(' . self::PARTIAL_ESCAPED_CHAR . '|[^\'\x00])*\'' .
66-
'|' . '\((' . self::PARTIAL_ESCAPED_CHAR . '|[^()\x00])*\))';
64+
public const PARTIAL_LINK_TITLE = '^(?:"(' . self::PARTIAL_ESCAPED_CHAR . '|[^"\x00])*+"' .
65+
'|' . '\'(' . self::PARTIAL_ESCAPED_CHAR . '|[^\'\x00])*+\'' .
66+
'|' . '\((' . self::PARTIAL_ESCAPED_CHAR . '|[^()\x00])*+\))';
6767

6868
public const REGEX_PUNCTUATION = '/^[!"#$%&\'()*+,\-.\\/:;<=>?@\\[\\]\\\\^_`{|}~\p{P}\p{S}]/u';
6969
public const REGEX_UNSAFE_PROTOCOL = '/^javascript:|vbscript:|file:|data:/i';

0 commit comments

Comments
 (0)