Phoenix500526 opened a new issue, #12103: URL: https://github.com/apache/arrow-rs/issues/12103
### Describe the bug `VariantDecimalType::try_new_with_signed_scale(1, i8::MIN)` panics when integer overflow checks are enabled, instead of returning an error for an unrepresentable rescaled value. This affects `VariantDecimal4`, `VariantDecimal8`, and `VariantDecimal16`. The shared implementation evaluates `-scale` as an `i8` before converting it to `u32`: ```rust let multiplier = <$native>::checked_pow(10, -scale as u32); ``` For scale -128, negation would produce 128, which does not fit in `i8`. The panic happens before `checked_pow` and the existing `Overflow when rescaling` error handling can run. [Source on main at bb47f8091e](https://github.com/apache/arrow-rs/blob/bb47f8091e5ac83117ce95942443e9bf391f2af1/parquet-variant/src/variant/decimal.rs#L186-L198). ### To Reproduce Create a small binary project: ```sh cargo new variant-scale-repro cd variant-scale-repro ``` Add this dependency to `Cargo.toml` under `[dependencies]` (pinned to the upstream revision containing the reproduced code): ```toml parquet-variant = { git = "https://github.com/apache/arrow-rs.git", rev = "bb47f8091e5ac83117ce95942443e9bf391f2af1" } ``` Replace `src/main.rs` with: ```rust use parquet_variant::{VariantDecimal4, VariantDecimalType}; fn main() { let result = VariantDecimal4::try_new_with_signed_scale(1, i8::MIN); println!("{result:?}"); } ``` Run the default debug build: ```sh cargo run ``` It panics inside the library; the example does not call `unwrap()`: ```text thread 'main' panicked at .../parquet-variant/src/variant/decimal.rs:264:1: attempt to negate with overflow ``` The same call also panics for `VariantDecimal8` and `VariantDecimal16` in debug builds. With the default release profile, `cargo run --release` instead returns: ```text Err(InvalidArgumentError("Overflow when rescaling 1 with scale -128")) ``` ### Expected behavior Return `Err` in both debug and release builds. The value represented by integer 1 at scale -128 is too large for these Variant decimal types, so rejection is expected, but the method should reach its existing checked error path rather than panic while computing the exponent. ### Additional context Using `u32::from(scale.unsigned_abs())` for the exponent would avoid overflowing the intermediate `i8` negation. Because this branch only handles negative scales, it preserves the intended exponent and lets `checked_pow` report overflow normally. The expression was introduced in #8562. This is separate from #12095, which concerns decimal precision validation rather than Variant rescaling. AI assistance: OpenAI Codex assisted with investigation, reproduction and drafting this report. The debug panic was reproduced locally for all three Variant decimal types, and the release result above was observed locally for `VariantDecimal4`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
