Skip to content

parse_decimal numeric overflow on long inputs #10787

Closed

Description

@neilconway

Describe the bug

See repro

To Reproduce

use arrow_array::types::Decimal128Type;
use arrow_cast::parse::parse_decimal;

// debug: panic "attempt to add with overflow"
// release: Ok(-75618303760208547436305468318170713657)
parse_decimal::<Decimal128Type>(&"1".repeat(256), 38, 0);

// debug: panic "attempt to multiply with overflow"
parse_decimal::<Decimal128Type>("1e99999", 10, 0);

Expected behavior

Both inputs should be rejected with an error, in both debug and release builds.

Additional context

No response

Activity

  1. added theissue type on Aug 21, 2026
  2. added
    bug
    on Aug 21, 2026
  3. neilconway commented on Aug 21, 2026

    @neilconway
    ContributorAuthor

    take

  4. Lstarsky0 commented on Aug 23, 2026

    @Lstarsky0
    Contributor

    Both panics are the bookkeeping counters overflowing, not the decimal value. result goes through mul_wrapping/add_wrapping the whole way and never panics on its own.

    There are four unchecked sites in this function, and the repro covers two of them:

    • digits: u8 (parse.rs:917, incremented at :953 and :988) — panics on the 256th significant digit. That's "1".repeat(256); 255 is fine.
    • exp: i16 (:808, exp *= 10 at :854) — that's 1e99999.
    • exp as u8 + digits at :1023, inside the non-e-notation precision check. This one fires earlier than the first: parse_decimal::<Decimal128Type>(&"1".repeat(246), 38, 10) panics at 246 digits, and 245 doesn't, because 10 + 246 leaves u8.
    • (digits as i16 + exp) at :889, the e-notation precision check. 1e32767 survives the exponent parse (it's exactly i16::MAX) and panics here instead.

    The release side is worse than one bad value. digits wraps mod 256, so the guard at :1030 (digits > precision) accepts anything whose significant-digit count is <= precision mod 256. With precision 38:

    254, 255 ones   Err
    256..294 ones   Ok(-75618303760208547436305468318170713657)
    295..511 ones   Err
    512..550 ones   Ok(same value)
    551 ones        Err
    

    so it's a periodic acceptance window rather than a tail case. Worth keeping in mind that :1030 can't be the backstop for this by itself, since the number it tests is the one that wrapped.

  5. added a commit that references this issue on Sep 1, 2026
    70219af
  6. added 3 commits that reference this issue on Sep 18, 2026
    f9eb4aa
    8bac2b6
    e9e1631
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions