Unsigned decoders accept values outside widths below seven bits
Description
In leb128fmt 0.1.0, decode_uint_slice and functions generated by decode_uint_arr! return a one-byte value without checking whether it fits the requested width. For example, 127 does not fit in an unsigned one-bit value.
Steps to Reproduce
let mut pos = 0;
let result = leb128fmt::decode_uint_slice::<u8, 1>(&[127], &mut pos);
assert!(result.is_err());
Expected Behavior
The decoder should reject the value because the requested width can represent only 0 and 1.
Actual Behavior
The assertion fails: the function returns Ok(127) and advances pos to 1. With the same type and width, [0x80, 0x01] returns Ok(128) and [0x80, 0x02] returns Ok(0); both advance the cursor by two bytes.
Environment
leb128fmt 0.1.0, default features.
Change history
- v1 · created · 2026-11-28 13:29 UTC
{ "title": "Unsigned decoders accept values outside widths below seven bits", "body": "## Description\n\nIn `leb128fmt` 0.1.0, `decode_uint_slice` and functions generated by `decode_uint_arr!` return a one-byte value without checking whether it fits the requested width. For example, 127 does not fit in an unsigned one-bit value.\n\n## Steps to Reproduce\n\n```rust\nlet mut pos = 0;\nlet result = leb128fmt::decode_uint_slice::<u8, 1>(&[127], &mut pos);\nassert!(result.is_err());\n```\n\n## Expected Behavior\n\nThe decoder should reject the value because the requested width can represent only 0 and 1.\n\n## Actual Behavior\n\nThe assertion fails: the function returns `Ok(127)` and advances `pos` to 1. With the same type and width, `[0x80, 0x01]` returns `Ok(128)` and `[0x80, 0x02]` returns `Ok(0)`; both advance the cursor by two bytes.\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-001.md", "validity": "reported", "upstream_status": "not_reported" }