proofs.rs

Partial parsing omits a single zero from the consumed length

Partial parsing omits a single zero from the consumed length

lexical_core::parse_partial_with_options

Found in Report #36 v1 · Updated 2026-11-10 07:02 UTC

Description

lexical_core::parse_partial_with_options reports too few consumed bytes for a single integer zero when the format sets no_integer_leading_zeros(true). The input is valid: forbidding leading zeros still permits a single zero. The same applies to the lexical-core integer FromLexicalWithOptions::from_lexical_partial_with_options implementations.

Prerequisites
  • Rust version: rustc 1.94.1 (e408947bf 2026-03-25)
  • lexical-core version: 1.0.6 (resolving lexical-parse-integer 1.0.6 and lexical-util 1.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 lexical_core::{NumberFormatBuilder, ParseIntegerOptions};

fn main() {
    const FORMAT: u128 = NumberFormatBuilder::new()
        .no_integer_leading_zeros(true)
        .build_strict();
    let result = lexical_core::parse_partial_with_options::<u8, FORMAT>(
        b"0",
        &ParseIntegerOptions::new(),
    );
    assert_eq!(result, Ok((0, 1))); // actual: Ok((0, 0))
}
Additional Context

The assertion fails with left: Ok((0, 0)), right: Ok((0, 1)). Signed b"-0" similarly returns Ok((0, 1)) instead of Ok((0, 2)). Standard-format parse_partial::<u8>(b"0") returns Ok((0, 1)), and the custom format consumes one byte for b"0!".

This is the existing symptom in #225, reproduced here through lexical-core 1.0.6. No new upstream issue has been filed.

Evidence

Change history
  1. v1 · created · 2026-11-10 07:02 UTC
    {
      "title": "Partial parsing omits a single zero from the consumed length",
      "body": "## Description\n\n`lexical_core::parse_partial_with_options` reports too few consumed bytes for a single integer zero when the format sets `no_integer_leading_zeros(true)`. The input is valid: forbidding leading zeros still permits a single zero. The same applies to the lexical-core integer `FromLexicalWithOptions::from_lexical_partial_with_options` implementations.\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 lexical_core::{NumberFormatBuilder, ParseIntegerOptions};\n\nfn main() {\n    const FORMAT: u128 = NumberFormatBuilder::new()\n        .no_integer_leading_zeros(true)\n        .build_strict();\n    let result = lexical_core::parse_partial_with_options::<u8, FORMAT>(\n        b\"0\",\n        &ParseIntegerOptions::new(),\n    );\n    assert_eq!(result, Ok((0, 1))); // actual: Ok((0, 0))\n}\n```\n\n## Additional Context\n\nThe assertion fails with `left: Ok((0, 0))`, `right: Ok((0, 1))`. Signed `b\"-0\"` similarly returns `Ok((0, 1))` instead of `Ok((0, 2))`. Standard-format `parse_partial::<u8>(b\"0\")` returns `Ok((0, 1))`, and the custom format consumes one byte for `b\"0!\"`.\n\nThis is the existing symptom in [#225](https://github.com/Alexhuszagh/rust-lexical/issues/225), reproduced here through lexical-core 1.0.6. No new upstream issue has been filed.",
      "evidence_url": "https://github.com/MasWag/crate-proofs/blob/e62defe37eef5b1f670f12f15574379fabca2cda/lexical-core/1.0.6/verification/findings/LC-001.md",
      "api_item_ids": [
        "47c163448094d8282d03bc500eff42a7f0a6fef4d79fcd29cb5d3b67ac9d4beb"
      ],
      "validity": "reported",
      "upstream_status": "not_reported"
    }

Read and join the discussion on the report →