Skip to content

Commit

Permalink
Fix two exponential backtracking issues
Browse files Browse the repository at this point in the history
  • Loading branch information
colinodell committed Mar 24, 2019
1 parent 81d1424 commit 9248319
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
- Modified how URL normalization decodes certain characters in order to align with the JS library's output
- Disallowed unescaped `(` in parenthesized link title

### Fixed

- Fixed two exponential backtracking issues

## [0.18.3] - 2019-03-21

This is a **security update** release.
Expand Down
4 changes: 2 additions & 2 deletions src/Util/LinkParserHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public static function parseLinkDestination(Cursor $cursor)
*/
public static function parseLinkLabel(Cursor $cursor)
{
$match = $cursor->match('/^\[(?:[^\\\\\[\]]|' . RegexHelper::PARTIAL_ESCAPED_CHAR . '|\\\\)*\]/');
if ($match === null || preg_match('/[^\\\\]\\\\\]$/', $match)) {
$match = $cursor->match('/^\[(?:[^\\\\\[\]]|\\\\.){0,1000}\]/');
if ($match === null) {
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Util/RegexHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ final class RegexHelper
const REGEX_WHITESPACE = '/[ \t\n\x0b\x0c\x0d]+/';
const REGEX_UNICODE_WHITESPACE_CHAR = '/^\pZ|\s/u';
const REGEX_THEMATIC_BREAK = '/^(?:(?:\*[ \t]*){3,}|(?:_[ \t]*){3,}|(?:-[ \t]*){3,})[ \t]*$/';
const REGEX_LINK_DESTINATION_BRACES = '/^(?:' . '[<](?:[^ <>\\t\\n\\\\\\x00]' . '|' . self::PARTIAL_ESCAPED_CHAR . '|' . '\\\\)*[>]' . ')/';
const REGEX_LINK_DESTINATION_BRACES = '/^(?:<(?:[^ <>\\t\\n\\\\\\x00]|\\\\.)*>)/';

/**
* @deprecated Instance methods will be removed in 0.18 or 1.0 (whichever comes first)
Expand Down

0 comments on commit 9248319

Please sign in to comment.