Fix content data stream concatenation mangling output in cfFilterPDFToPDF #56
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.
When running the following command on example.pdf
./pdftopdf 1 1 1 1 "" example.pdf > output.pdf
the resultant output.pdf is mangled.
This is better explained in this bug report.
It seems that the logic that provides the content data streams and concatenates them to form a single stream in an XObject is assuming a correct separation between the contents of successive streams.
To better illustrate: in example.pdf above (note that the sample pdf's have been run through
qpdf --qdf --recompress-flate --compress-streams=n --object-streams=disable
for illustration purposes), page 1's contents areand looking at objects 9-11:
This results in the following in output.pdf above:
so the concatenation of streams 9 and 11 result in the (invalid) command 'qq', confusing pdf parsers and mangling the output.
With the patch applied, the output becomes
I'm not sure if this is the best solution for the problem, but hopefully the analysis can at least point to that.