Skip to content

[Bug Report]: Mardown image data URI extraction fails on large images due to regex match limits #3249

Description

@ssddanbrown

Describe the Bug

Regex match limits cause large embedded image data uris, within markdown content, not to be extracted due to reaching the limits of PHP regex pattern matching.

Verified by attempting to upload 3MB of data uri, which triggered issue.
Adding the below, just before the regex ran, would then allow this 3MB file to work fine.

ini_set("pcre.backtrack_limit", "23001337");
ini_set("pcre.recursion_limit", "23001337");

Need to use a more efficient solution for parsing the image data uris.
Maybe a loop over strtok to with some simple tracking would be best.

Ideally needs a test to cover.

HTML unaffected due to using a parser instead of regex.

Regex location:

preg_match_all('/!\[.*?]\(.*?(data:image\/.*?)[)"\s]/', $markdown, $matches);

As reported by @SteveDinn here: #2898 (comment)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions