misd-service-development / php-linkify

Converts URLs and email addresses into HTML links
MIT License
112 stars 17 forks source link

Fix catastrophic backtracking #21

Closed bartgloudemans closed 7 years ago

bartgloudemans commented 7 years ago

Fixes issue https://github.com/misd-service-development/php-linkify/issues/14 by applying atomic-grouping to prevent catastrophic backtracking.

Edge case:
https://www.example.com/a_(aaaaaaaaaaaaaaaaa) with 17 chars inside parentheses results in a PREG_BACKTRACK_LIMIT_ERROR

Similar strings result in a successful match https://www.example.com/a_(aaaaaaaaaaaaaaaa) with 16 chars inside parentheses
https://www.example.com/a_(aaaaaaaaaaaaaaaaa)b with 17 chars inside parentheses together with trailing character

Tests have been added which address the now solved edge case together with its sibling cases.

The following fork already contains the fix: https://github.com/lode/php-linkify/

thewilkybarkid commented 7 years ago

Thanks!