#1298 - Fix in LZWDecoder when valid PDF stream data does not start with LZW Clear Table code (256) #1299
+378
−26
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.
This problem occurs in PostScript calculator functions in several PDFs we have encountered, changes include unit tests to cover both common LZW and this more uncommon scenario.
Description of the new Feature/Bugfix
The fix is really a simplification of the main decoding loop in LZWDecoder and detecting explicitly when there is no "oldCode", i.e. previous code. Hopefully the decode() method is slightly easier to follow now and supports this valid scenario where the LZW encoded data does not start with the Clear Table (256) special code.
Related Issue: #1298
Unit-Tests for the new Feature/Bugfix
Three unit tests were added:
Compatibilities Issues
No compatibility issues or changes to function signatures. Fix is internal to
LZWDecoer.decode()
methodYour real name
Scott More
Testing details
Nothing specific. All PDFs with LZW decode streams should work with no data corruption or exceptions now.