Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catastrofic backtracking in regex crashes feed read #425

Open
DemonTPx opened this issue Apr 9, 2024 · 0 comments · May be fixed by #426
Open

Catastrofic backtracking in regex crashes feed read #425

DemonTPx opened this issue Apr 9, 2024 · 0 comments · May be fixed by #426

Comments

@DemonTPx
Copy link

DemonTPx commented Apr 9, 2024

When I try to read the golang blog feed using version 6.0.3, it crashes with the following error:

preg_replace(): Argument #3 ($subject) must be of type array|string, null given

The error originates from FeedIo\Feed\Node line 158, where $this->content has been set to null by the preg_replace on the line before:

$this->content = preg_replace('!(<*\s*[^>]*)(href=)(.?)(\/[^\/])!','\1 href=\3'.$host.'\4', $this->content );

The preg_replace may return null on error and the error we get here is: PREG_BACKTRACK_LIMIT_ERROR (2) "Backtrack limit exhausted"

I've tried this regex using regex101 with the content of the item from the feed which can be seen here: https://regex101.com/r/yJzfz1/1

My pcre.backtrack_limit setting is set to the default 1.000.000.

It seems to me that the backtrack error gets exponentially worse for every byte the content gets bigger.

A possible solution would be to check if the preg_replace results in an error and skip the replace when it does, so the content isn't set to null. Another would be to optimize the regex pattern, but I'm not sure how. And another (hacky) solution might be to limit the content size beforehand...

My solution for now is to downgrade debril/feed-io to 5.2, where this preg_replace has not been merged yet...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant