[X] Bug fix (involves code and configuration changes)
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
[X] Please add at least one test case (unit test, system test, ...) to demonstrate that the change is working. If existing code was changed, your tests cover these code parts as well.
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
.