Skip to content

Strip inline data URIs before conversion to avoid backtrack limit failures - #132

Open
samipuro wants to merge 1 commit into
mtibben:masterfrom
samipuro:fix/strip-data-uri-images
Open

samipuro wants to merge 1 commit into
mtibben:masterfrom
samipuro:fix/strip-data-uri-images

Conversation

@samipuro

Copy link
Copy Markdown

Fixes #130.

A large inline image (<img src="data:image/png;base64,...">) inside an element converted with a lazy pattern, such as <li>(.*?)</li> or <a ...>(.*?)</a>, exhausts the PCRE backtrack limit. preg_replace() then returns null, and getText() silently returns an empty string, with only deprecation notices from preg_replace_callback() and strip_tags().

The image source is never part of the text output, so doConvert() now empties data: URIs in img src attributes before the conversion. It uses a possessive pattern, so this step itself runs in linear time. Alt text is still rendered as before.

DataUriTest covers a 1.3 MB image in a list item, in a link and in a paragraph. The list item and link cases return an empty string on master.

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 this pull request may close these issues.

Unhandled catostrophic backtracking.

1 participant