Repository navigation
Conversation
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.
What is wrong
A 16-byte integer with the top bit set is read as a huge positive number. It should be negative.
Apple's
CFBinaryPList.csays 1, 2 and 4-byte integers are unsigned, and 8-byte integers are signed "(and 16-byte when available)". Python'splistlibdoes the same (signed=tokenL >= 3). This parser only applied the sign for 8 bytes.Repro: take
plistlib.dumps([2**64 - 1], fmt=plistlib.FMT_BINARY)and replace the 16 integer bytes with(-5).to_bytes(16, 'big', signed=True).plistlib.loads(...)gives[-5]bplist.parseBuffer(...)gives[340282366920938463463374607431768211451n](2^128 - 5)The fix
In
readInteger, apply the sign for both 8 and 16-byte integers: subtract2^(bytes * 8)when the top bit is set. Positive 16-byte values (like2^64 - 1, which plistlib writes as 16 bytes) are not changed.The test
Added
signed 128-bit integersnext to the 64-bit test, using the existingmakeIntegerArrayhelper. It covers -1, -5, -2^63 - 1, -2^127 and 2^127 - 1.npm run lint,npm run typecheckandnpm run smokepass. I also ran 2000 random plists made byplistlibthrough the parser; there was no difference before or after.