Suffix format advances past an unrelated invalid byte
lexical_core::parse_partial_with_options, lexical_core::parse_with_options
Description
With a base suffix configured, lexical_core::parse_partial_with_options can count an unrelated invalid byte as consumed when another byte follows it. lexical_core::parse_with_options then reports the following byte as the invalid digit. The configured suffix in the example is h; ? should terminate the number at index 2. The lexical-core integer FromLexicalWithOptions methods forward to the same parser.
Prerequisites
- Rust version:
rustc 1.94.1 (e408947bf 2026-03-25) - lexical-core version:
1.0.6(resolving lexical-parse-integer1.0.6and lexical-util1.0.7) - Features:
parse-integers,format,power-of-two; default features disabled
[dependencies]
lexical-core = { version = "=1.0.6", default-features = false, features = ["parse-integers", "format", "power-of-two"] }
Test case
use core::num::NonZeroU8;
use lexical_core::{NumberFormatBuilder, ParseIntegerOptions};
fn main() {
const FORMAT: u128 = NumberFormatBuilder::new()
.base_suffix(NonZeroU8::new(b'h'))
.build_strict();
let result = lexical_core::parse_partial_with_options::<u8, FORMAT>(
b"12?x",
&ParseIntegerOptions::new(),
);
assert_eq!(result, Ok((12, 2))); // actual: Ok((12, 3))
}
Additional Context
The assertion fails with left: Ok((12, 3)), right: Ok((12, 2)). For the same input and format, complete parsing returns Err(InvalidDigit(3)) instead of Err(InvalidDigit(2)).
Controls: b"12?" consumes two bytes; b"12h?" consumes three bytes, including the actual suffix. The extra consumption occurs when an unrelated invalid byte has another byte after it.
Change history
- v1 · created · 2026-11-10 07:02 UTC
{ "title": "Suffix format advances past an unrelated invalid byte", "body": "## Description\n\nWith a base suffix configured, `lexical_core::parse_partial_with_options` can count an unrelated invalid byte as consumed when another byte follows it. `lexical_core::parse_with_options` then reports the following byte as the invalid digit. The configured suffix in the example is `h`; `?` should terminate the number at index 2. The lexical-core integer `FromLexicalWithOptions` methods forward to the same parser.\n\n## Prerequisites\n\n- Rust version: `rustc 1.94.1 (e408947bf 2026-03-25)`\n- lexical-core version: `1.0.6` (resolving lexical-parse-integer `1.0.6` and lexical-util `1.0.7`)\n- Features: `parse-integers`, `format`, `power-of-two`; default features disabled\n\n```toml\n[dependencies]\nlexical-core = { version = \"=1.0.6\", default-features = false, features = [\"parse-integers\", \"format\", \"power-of-two\"] }\n```\n\n## Test case\n\n```rust\nuse core::num::NonZeroU8;\nuse lexical_core::{NumberFormatBuilder, ParseIntegerOptions};\n\nfn main() {\n const FORMAT: u128 = NumberFormatBuilder::new()\n .base_suffix(NonZeroU8::new(b'h'))\n .build_strict();\n let result = lexical_core::parse_partial_with_options::<u8, FORMAT>(\n b\"12?x\",\n &ParseIntegerOptions::new(),\n );\n assert_eq!(result, Ok((12, 2))); // actual: Ok((12, 3))\n}\n```\n\n## Additional Context\n\nThe assertion fails with `left: Ok((12, 3))`, `right: Ok((12, 2))`. For the same input and format, complete parsing returns `Err(InvalidDigit(3))` instead of `Err(InvalidDigit(2))`.\n\nControls: `b\"12?\"` consumes two bytes; `b\"12h?\"` consumes three bytes, including the actual suffix. The extra consumption occurs when an unrelated invalid byte has another byte after it.", "evidence_url": "https://github.com/MasWag/crate-proofs/blob/e62defe37eef5b1f670f12f15574379fabca2cda/lexical-core/1.0.6/verification/findings/LC-002.md", "api_item_ids": [ "47c163448094d8282d03bc500eff42a7f0a6fef4d79fcd29cb5d3b67ac9d4beb", "043cd694d4cdfaf071cb92f9f121703a7cdf8ed84c8252f650d5ca08fa2942e7" ], "validity": "reported", "upstream_status": "not_reported" }