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.
The
varint::check
helper accepts itsencoded
argument mutably, which means its implementation is at risk of lettingdecode_varint
deplete bytes from itsencoded
argument beforedecode_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 thatdecode_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.