apache / apache/arrow-rs

temporal cast overflows/panics

Open
#10,131 6 comments 0 reactions 1 assignee Claimed by @yinli-systems View on GitHub
bug
Dominant language
Rust
Stars
3.6k
Forks
1.3k
Avg merge
2d 16h
Merged PRs (30d)
168

Description

### Describe the bug

some of the cast paths (for temporal types like time/date/timestamp) don't protect against overflows/underflows/panics properly.

### To Reproduce

```rust
// arrow-cast/src/cast/mod.rs
#[test]
fn test123() {
let a = Date64Array::from(vec![i64::MAX]);
let b = cast(&a, &DataType::Date32).unwrap();
let b = b.as_primitive::();
dbg!(b.value(0)); // outputs -622191233

let a = Time32SecondArray::from(vec![i32::MAX]);
let _ = cast(&a, &DataType::Time32(TimeUnit::Millisecond));
}
```

output of test

```sh
running 1 test
[arrow-cast/src/cast/mod.rs:13904:9] b.value(0) = -622191233

thread 'cast::tests::test123' (6354242) panicked at arrow-cast/src/cast/mod.rs:1722:56:
attempt to multiply with overflow
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
test cast::tests::test123 ... FAILED

failures:

failures:
cast::tests::test123

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 352 filtered out; finished in 0.00s

error: test failed, to rerun pass `-p arrow-cast --lib`
```

### Expected behavior

for the date64 -> date32, we underflow to a negative value. we should respect the cast safety option (either null it or explicitly error)

for time32 second -> time32 milli it panics. same as above, we should respect the cast safety option.

### Additional context

inspired by https://github.com/apache/arrow-rs/issues/9824

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.