Skip to content

as_i128 accepts u64 values above i64::MAX - #69

Open
yuxi-liu-wired wants to merge 1 commit into
simd-lite:mainfrom
yuxi-liu-wired:pr/as-i128
Open

yuxi-liu-wired wants to merge 1 commit into
simd-lite:mainfrom
yuxi-liu-wired:pr/as-i128

Conversation

@yuxi-liu-wired

Copy link
Copy Markdown

fix: as_i128 accepts u64 values above i64::MAX

The default ValueAsScalar::as_i128 went through as_i64, so every
u64 above i64::MAX gave None, although each one fits in an i128.
as_u128 (through as_u64) has no such gap, and the 128bit
implementation on StaticNode already handles it.

User-visible through simd-json without the 128bit feature:

simd_json::serde::from_slice::<i128>(b"9223372036854775808")
    before: Err(ExpectedSigned)    now: Ok(9223372036854775808)

(serde_json and sonic-rs accept it.)

Test: node::tests::as_i128_covers_every_integer (fails before this
change).

Testing

Each commit adds a regression test that fails before the change. The full test suite passes and
cargo fmt --check is clean on the changed files.

Found with a differential fuzzer comparing serde_json, simd-json, sonic-rs and jiter.

The default `ValueAsScalar::as_i128` went through `as_i64`, so every
u64 above `i64::MAX` gave `None`, although each one fits in an i128.
`as_u128` (through `as_u64`) has no such gap, and the `128bit`
implementation on `StaticNode` already handles it.

User-visible through simd-json without the `128bit` feature:

    simd_json::serde::from_slice::<i128>(b"9223372036854775808")
        before: Err(ExpectedSigned)    now: Ok(9223372036854775808)

(serde_json and sonic-rs accept it.)

Test: `node::tests::as_i128_covers_every_integer` (fails before this
change).

Found by a three-way differential fuzzer (serde_json, simd-json,
sonic-rs).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants