tokio-rs / prost

PROST! a Protocol Buffers implementation for the Rust Language
Apache License 2.0
3.78k stars 489 forks source link

really test decode_varint_slow #977

Closed mumbleskates closed 6 months ago

mumbleskates commented 7 months ago

The varint::check helper accepts its encoded argument mutably, which means its implementation is at risk of letting decode_varint deplete bytes from its encoded argument before decode_varint_slow is tested. This is the cause for the awkward code from 2021, including <&[u8]>::clone(&encoded). However, this test is expecting success, so the code was forced to work.

The varint_overflow test, however, expects failure. It was not noticed until now that decode_varint_slow(&mut u64_max_plus_one) on line 1687 always attempts to decode an empty slice &[] and fails to decode for that reason, rather than testing what happens whan it attempts to decode an over-max varint.

This changes all the buffers in question to not be declared mutably, and instead reborrows them to clone the slice.