Closed jamesbornholt closed 4 years ago
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.
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.