Skip to content

Commit

Permalink
Fix catastrophic backtracking when parsing link labels/titles
Browse files Browse the repository at this point in the history
  • Loading branch information
colinodell committed Dec 7, 2024
1 parent 71f63e9 commit e7584cf
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ Updates should follow the [Keep a CHANGELOG](https://keepachangelog.com/) princi
- Fixed quadratic complexity finding the bottom opener for emphasis and strikethrough delimiters
- 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)
- Fixed quadratic complexity deactivating link openers
- Fixed catastrophic backtracking when parsing link labels/titles

## [2.4.1] - 2023-08-30

Expand Down
2 changes: 1 addition & 1 deletion src/Util/LinkParserHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static function parseLinkLabel(Cursor $cursor): int

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

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Util/RegexHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ final class RegexHelper
self::PARTIAL_PROCESSINGINSTRUCTION . '|' . self::PARTIAL_DECLARATION . '|' . self::PARTIAL_CDATA . ')';
public const PARTIAL_HTMLBLOCKOPEN = '<(?:' . self::PARTIAL_BLOCKTAGNAME . '(?:[\s\/>]|$)' . '|' .
'\/' . self::PARTIAL_BLOCKTAGNAME . '(?:[\s>]|$)' . '|' . '[?!])';
public const PARTIAL_LINK_TITLE = '^(?:"(' . self::PARTIAL_ESCAPED_CHAR . '|[^"\x00])*"' .
'|' . '\'(' . self::PARTIAL_ESCAPED_CHAR . '|[^\'\x00])*\'' .
'|' . '\((' . self::PARTIAL_ESCAPED_CHAR . '|[^()\x00])*\))';
public const PARTIAL_LINK_TITLE = '^(?:"(' . self::PARTIAL_ESCAPED_CHAR . '|[^"\x00])*+"' .
'|' . '\'(' . self::PARTIAL_ESCAPED_CHAR . '|[^\'\x00])*+\'' .
'|' . '\((' . self::PARTIAL_ESCAPED_CHAR . '|[^()\x00])*+\))';

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

0 comments on commit e7584cf

Please sign in to comment.