Repository navigation
parser: accept /P written as an unsigned 32-bit integer - #295
Closed
apollo-2006 wants to merge 1 commit into
Closed
apollo-2006 wants to merge 1 commit into
apollo-2006 wants to merge 1 commit into
Conversation
/P is a 32-bit flag word that the spec reads as unsigned, and some producers write it that way (4294967292 rather than -4). Integer tokens were parsed with to::<i32>(), so such a file could not be opened. Parse as i32 and fall back to u32, keeping the same bits. Values above u32::MAX are still an error. Fixes pdf-rs#293
Contributor
|
fixed in b9327bb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
/Pis a 32-bit flag word that the spec says to read as unsigned, and some producers write it that way:/P 4294967292rather than-4. The parser reads integer tokens withto::<i32>(), which fails on that value, so the encryption dictionary never parses and the file cannot be opened with any password.As suggested on the issue, this reads such values as negative numbers. A small
parse_integerhelper, used at the two places the parser builds aPrimitive::Integer, triesi32first and falls back tou32, keeping the same bits, so4294967292becomes-4. Anything aboveu32::MAXor belowi32::MINis still an error. Every value it can produce could already come from a negative literal, so nothing downstream sees anything new, and since the value is still ani32it is written back out as-4.Testing:
parser::testsparses an array that goes through both call sites (reverting either one makes it fail),/P 4294967292in a dictionary, and theu32::MAX + 1error.bad-encrypted.pdffrom the issue now opens with the passwordfoo, likegood-encrypted.pdf. For comparison, poppler'spdfinfoopens both and reports the same permissions for each.cargo test --workspacepasses.Fixes #293