Signed slice encoders accept values outside the requested width
Description
In leb128fmt 0.1.0, encode_sint_slice and encode_fixed_sint_slice accept some values outside the requested signed width. In particular, 128 cannot be represented as a signed 8-bit value.
Steps to Reproduce
let mut output = [0; 2];
let mut pos = 0;
let result = leb128fmt::encode_sint_slice::<i16, 8>(128, &mut output, &mut pos);
assert_eq!(result, None);
Expected Behavior
The encoder should return None: the signed 8-bit range is -128 through 127.
Actual Behavior
The assertion fails: the function returns Some(2), writes [0x80, 0x01], and advances pos to 2. The fixed-length slice encoder also accepts this value. With width 7, value 127, and a one-byte output, the fixed encoder panics while attempting to write a second byte.
Environment
leb128fmt 0.1.0, default features.
Change history
- v1 · created · 2026-11-28 13:29 UTC
{ "title": "Signed slice encoders accept values outside the requested width", "body": "## Description\n\nIn `leb128fmt` 0.1.0, `encode_sint_slice` and `encode_fixed_sint_slice` accept some values outside the requested signed width. In particular, 128 cannot be represented as a signed 8-bit value.\n\n## Steps to Reproduce\n\n```rust\nlet mut output = [0; 2];\nlet mut pos = 0;\nlet result = leb128fmt::encode_sint_slice::<i16, 8>(128, &mut output, &mut pos);\nassert_eq!(result, None);\n```\n\n## Expected Behavior\n\nThe encoder should return `None`: the signed 8-bit range is -128 through 127.\n\n## Actual Behavior\n\nThe assertion fails: the function returns `Some(2)`, writes `[0x80, 0x01]`, and advances `pos` to 2. The fixed-length slice encoder also accepts this value. With width 7, value 127, and a one-byte output, the fixed encoder panics while attempting to write a second byte.\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-002.md", "validity": "reported", "upstream_status": "not_reported" }