Skip to content

fix: handle lead/lag extreme offset overflow cases (#22221, #22231)#375

Open
Dandandan wants to merge 2 commits into
mainfrom
codex/fix-issues-22231-and-22221-in-datafusion
Open

fix: handle lead/lag extreme offset overflow cases (#22221, #22231)#375
Dandandan wants to merge 2 commits into
mainfrom
codex/fix-issues-22231-and-22221-in-datafusion

Conversation

@Dandandan

Copy link
Copy Markdown
Owner

Motivation

  • Prevent panics and overflow when lead/lag are used with extreme offsets such as i64::MIN and i64::MAX by handling those edge cases explicitly.
  • Ensure lead/lag evaluation returns the configured default value or a descriptive error instead of crashing during planning or execution.

Description

  • Change WindowShiftKind::shift_offset to return Result<i64> and use checked_neg for lead to detect and reject i64::MIN with a DataFusionError::Execution error.
  • Update partition_evaluator to propagate the new Result from shift_offset and keep the reversal logic intact when needed.
  • Replace unchecked index arithmetic in WindowShiftEvaluator::evaluate with checked_sub and safe usize conversion so extreme offsets do not overflow and out-of-range indices map to the default value.
  • Remove an unused import and add two regression unit tests: test_lead_i64_min_offset_returns_error and test_lead_i64_max_offset_evaluate_returns_default to cover both issue cases.

Testing

  • Ran cargo fmt --all which completed successfully.
  • Ran cargo clippy --all-targets --all-features -- -D warnings, which reported a pre-existing unrelated compilation error in datafusion/physical-plan/benches/aggregate_vectorized.rs and therefore did not fully complete in this environment.
  • Added unit tests under datafusion/functions-window for the regressions; full test execution in CI is recommended to validate across the repository's build matrix.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant