Check for binary content in formatContent() before a problematic regexp #676
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Type of pull request
About
Some PDF files manage to serve binary content (a font, or an image, etc.) to the
formatContent()
method which only accepts text document streams.Since
(strings)
in PDF document streams can contain binary content (that gets decoded by a font library, for instance) we must test the document stream for text-only content EXCLUDING(string)
content.Previously the check for text-only content was done after a regexp removing the
(strings)
from the stream, recursively extending the regexp to check for balanced parentheses. However for a sufficiently long binary stream, this might create a regexp long enough to cause a PHP error.The solution is to move the check for binary content before this
(string)
-removing regexp. Simplify the binary check by truncating the document stream at the first open parenthesis, which indicates the start of a(string)
, then testing what remains for valid UTF-8.This makes the later check for binary content unnecessary and it has been removed. Resolves issue #668.
Future work on this issue should be done to determine why PdfParser is creating PDFObject objects from binary data in the first place.
Checklist for code / configuration changes
fixes #1234
to outline that you are providing a fix for the issue#1234
.