You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
parse_decimal numeric overflow on long inputs #10787
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.
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 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:
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.
Activity
neilconway commentedon Aug 21, 2026
take
Lstarsky0 commentedon Aug 23, 2026
Both panics are the bookkeeping counters overflowing, not the decimal value.
resultgoes throughmul_wrapping/add_wrappingthe 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:953and:988) — panics on the 256th significant digit. That's"1".repeat(256); 255 is fine.exp: i16(:808,exp *= 10at:854) — that's1e99999.exp as u8 + digitsat: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, because10 + 246leavesu8.(digits as i16 + exp)at:889, the e-notation precision check.1e32767survives the exponent parse (it's exactlyi16::MAX) and panics here instead.The release side is worse than one bad value.
digitswraps mod 256, so the guard at:1030(digits > precision) accepts anything whose significant-digit count is<= precisionmod 256. With precision 38:so it's a periodic acceptance window rather than a tail case. Worth keeping in mind that
:1030can't be the backstop for this by itself, since the number it tests is the one that wrapped.Consolidate string-to-decimal parsing into a single code path
fix: Consolidate string-to-decimal parsing into a single code path (#…
fix: Consolidate string-to-decimal parsing into a single code path (a…
fix: Consolidate string-to-decimal parsing into a single code path (a…
fix: Consolidate string-to-decimal parsing into a single code path (a…