kosiew opened a new issue, #7886:
URL: https://github.com/apache/arrow-rs/issues/7886

   **Describe the bug**
   <!--
   A clear and concise description of what the bug is.
   -->
   
   When attempting to cast a large `Decimal256` value to `Float64`, Arrow 
panics due to an unchecked `.unwrap()` on a `None` result from `to_f64()`. This 
occurs because some large `Decimal256` values cannot be represented accurately 
as `f64`, and the conversion fails silently, leading to a runtime panic.
   
   
   **To Reproduce**
   <!--
   Steps to reproduce the behavior:
   -->
   
   This was encountered via 
[DataFusion](https://github.com/apache/datafusion/issues/16689)
   
   ```sql
   > create table tt(v1 decimal(50,2));
   > insert into tt values (133333333333333333333333333333333333333333333.34);
   > select v1 + 1.5 from tt;
   
   thread 'main' panicked at 
/Users/yongting/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/arrow-cast-55.2.0/src/cast/mod.rs:894:38:
   called `Option::unwrap()` on a `None` value
   note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
   ```
   
   The panic comes from
   
https://github.com/apache/arrow-rs/blob/3126dad0348035bc5fadc8ec61b7150b9ce6aad5/arrow-cast/src/cast/mod.rs#L894
   
   
   **Expected behavior**
   <!--
   A clear and concise description of what you expected to happen.
   -->
   Avoid using .unwrap() in the cast logic.
   Potential alternatives:
   
   Gracefully propagate the error:
   ```rust
   |x: i256| x.to_f64().ok_or_else(|| ArrowError::CastError("Failed to convert 
Decimal256 to f64".to_string()))
   ```
   
   
   **Additional context**
   <!--
   Add any other context about the problem here.
   -->
   This issue was discovered via [SQLancer 
fuzzing](https://github.com/apache/datafusion/issues/11030), which uncovered 
this unsafe conversion path. Avoiding panics in core Arrow casting logic would 
improve robustness in downstream libraries like DataFusion.


-- 
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]

Reply via email to