Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Catastrofic backtracking in regex crashes feed read #425

@DemonTPx

Description

@DemonTPx

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...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions