Skip to content

Fix VarInt decoding with extra bytes at the end#13

Merged
dermesser merged 1 commit intodermesser:masterfrom
jamesbornholt:master
Oct 22, 2020
Merged

Fix VarInt decoding with extra bytes at the end#13
dermesser merged 1 commit intodermesser:masterfrom
jamesbornholt:master

Conversation

@jamesbornholt
Copy link
Copy Markdown
Contributor

After #10, decoding a VarInt from a slice can fail if the final byte of the slice has its MSB set, even if the VarInt decoding will never make it that far. This is an issue if we're decoding from a larger slice that has other encoded data after the VarInt.

It's not enough to check the last byte of the slice for the MSB being set -- we have to scan all the bytes and try to decode them, and only fail decoding if we never saw the MSB set in any byte.

It's not enough to check the last byte of the slice for the MSB being
set -- we have to scan all the bytes, and only fail decoding if we never
saw the MSB set in any byte.
@jamesbornholt
Copy link
Copy Markdown
Contributor Author

I realized I forgot to make the same change for i64, which is done now.

I also added another test for overflow (encodings that are too long to produce a valid u64/i64), which exposed an off-by-one in the conditional: shift > (10 * 7) should be shift > (9 * 7) to avoid trying to do a shift by > 64 bits.

@dermesser dermesser merged commit 8ec9a9e into dermesser:master Oct 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants