Decoders mishandle continuation at a seven-bit width
Description
In leb128fmt 0.1.0, a function generated by decode_uint_arr! for a seven-bit width panics when the only input byte has its continuation bit set. At the same width, decode_uint_slice and decode_sint_slice can consume an extra byte instead of rejecting the continuation.
Steps to Reproduce
leb128fmt::decode_uint_arr!(decode_u7, u8, 7);
assert_eq!(decode_u7([0x80]), None);
Expected Behavior
The array has no terminating byte, so the decoder should return None for the incorrect encoding.
Actual Behavior
The call panics with an index-out-of-bounds error (index 1, length 1). For [0xff, 0x00], the slice decoders with width 7 return Ok(127) and advance the cursor by two bytes. The signed result also exceeds the signed seven-bit range of -64 through 63.
Environment
leb128fmt 0.1.0, default features.
Change history
- v1 · created · 2026-11-28 13:29 UTC
{ "title": "Decoders mishandle continuation at a seven-bit width", "body": "## Description\n\nIn `leb128fmt` 0.1.0, a function generated by `decode_uint_arr!` for a seven-bit width panics when the only input byte has its continuation bit set. At the same width, `decode_uint_slice` and `decode_sint_slice` can consume an extra byte instead of rejecting the continuation.\n\n## Steps to Reproduce\n\n```rust\nleb128fmt::decode_uint_arr!(decode_u7, u8, 7);\nassert_eq!(decode_u7([0x80]), None);\n```\n\n## Expected Behavior\n\nThe array has no terminating byte, so the decoder should return `None` for the incorrect encoding.\n\n## Actual Behavior\n\nThe call panics with an index-out-of-bounds error (index 1, length 1). For `[0xff, 0x00]`, the slice decoders with width 7 return `Ok(127)` and advance the cursor by two bytes. The signed result also exceeds the signed seven-bit range of -64 through 63.\n\n## Environment\n\n`leb128fmt` 0.1.0, default features.", "evidence_url": "https://github.com/MasWag/crate-proofs/blob/bb7e96e52ff285bca94443d090899706c2f127ec/leb128fmt/0.1.0/verification/findings/LEB128FMT-004.md", "validity": "reported", "upstream_status": "not_reported" }