Closed sollyucko closed 1 year ago
Hi; thanks for the PR! However, to the best of my own knowledge, negative numbers should always be 10-byte varints (which decodes to a 64 bit result). This is from generally looking online (such as here) as well as the official documentation (which I think now has rephrased the section on negative numbers after the previous links quoted it):
The
intN
types encode negative numbers as two's complement, which means that, as unsigned, 64-bit integers, they have their highest bit set. As a result, this means that all ten bytes must be used.
I've tested it with the following pseudo-fuzzing code snippet, which passes with the current code but doesn't with as u32 as u64
.
Do let me know if I've missed anything / misunderstood your PR though!
-...i32 as u64
results in sign-extending all the way to 64 bits, which I assume is incorrect according to the protobuf spec. Changing it toas u32 as u64
should sign-extend to 32 bits and then zero-extend from there to 64 bits, resulting in what I assume is the correct behavior.Demo: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=dc9845eb3a846f6658029234ab801478