Skip to content

fix(arrow-cast): respect cast safety for overflowing temporal casts#10162

Open
SAY-5 wants to merge 1 commit into
apache:mainfrom
SAY-5:fix/temporal-cast-overflow-10131
Open

fix(arrow-cast): respect cast safety for overflowing temporal casts#10162
SAY-5 wants to merge 1 commit into
apache:mainfrom
SAY-5:fix/temporal-cast-overflow-10131

Conversation

@SAY-5

@SAY-5 SAY-5 commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Two temporal cast paths ignore the cast safety option:

  • Time32(Second) to Time32(Millisecond) multiplies an i32 by 1000 with unary, so a large value panics with "attempt to multiply with overflow" in debug and wraps in release.
  • Date64 to Date32 divides by MILLISECONDS_IN_DAY and then does an unchecked as i32, which silently truncates day counts that do not fit in i32 (e.g. i64::MAX produces -622191233).

Both are reachable from cast/cast_with_options on valid input and do not honour CastOptions::safe.

What changes are included in this PR?

Both casts now follow the same pattern already used elsewhere in this file (for decimal and timestamp casts): in safe mode out-of-range values become null via unary_opt with a checked operation, and in non-safe mode they return a CastError/ArithmeticOverflow via try_unary.

This covers the two cases shown in the issue. Other temporal casts that multiply into i64 (e.g. Time32(Second) to Time64) cannot overflow for in-range inputs and are left unchanged.

Are these changes tested?

Yes. Added test_cast_date64_to_date32_overflow and test_cast_time32_second_to_time32_millisecond_overflow, each checking that the safe cast nulls the out-of-range value and the non-safe cast errors instead of panicking or truncating. The existing temporal cast tests still pass.

Are there any user-facing changes?

These two casts no longer panic or silently truncate on overflow. Safe casts now yield null and non-safe casts return an error for the affected inputs.

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
@github-actions github-actions Bot added the arrow Changes to the arrow crate label Jun 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow Changes to the arrow crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants