Skip to content

date_bin() panics on large inputs #20219

Closed

Description

@neilconway

Describe the bug

Found via fuzzing.

To Reproduce

select DATE_BIN('1637426858', TO_TIMESTAMP_MILLIS(1040292460), TIMESTAMP '1984-01-07 00:00:00');

Yields

thread 'main' (43082114) panicked at /Users/neilconway/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/chrono-0.4.43/src/datetime/mod.rs:1750:38:
`DateTime - Months` out of range
stack backtrace:
   0: __rustc::rust_begin_unwind
             at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/std/src/panicking.rs:698:5
   1: core::panicking::panic_fmt
             at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/core/src/panicking.rs:80:14
   2: core::panicking::panic_display
             at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/core/src/panicking.rs:264:5
   3: core::option::expect_failed
             at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/core/src/option.rs:2183:5
   4: core::option::Option<T>::expect
             at /Users/neilconway/.rustup/toolchains/1.92.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/option.rs:970:21
   5: <chrono::datetime::DateTime<Tz> as core::ops::arith::Sub<chrono::month::Months>>::sub
             at /Users/neilconway/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/chrono-0.4.43/src/datetime/mod.rs:1750:38
   6: datafusion_functions::datetime::date_bin::date_bin_months_interval
             at ./datafusion/functions/src/datetime/date_bin.rs:358:9
   7: datafusion_functions::datetime::date_bin::date_bin_impl::stride_map_fn::{{closure}}
             at ./datafusion/functions/src/datetime/date_bin.rs:557:23
[...]
select DATE_BIN('1637426858', TO_TIMESTAMP_MILLIS(-1040292460), TIMESTAMP '1984-01-07 00:00:00');

Yields

thread 'main' (43083083) panicked at datafusion/functions/src/datetime/date_bin.rs:380:42:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0: __rustc::rust_begin_unwind
             at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/std/src/panicking.rs:698:5
   1: core::panicking::panic_fmt
             at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/core/src/panicking.rs:80:14
   2: core::panicking::panic
             at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/core/src/panicking.rs:150:5
   3: core::option::unwrap_failed
             at /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/core/src/option.rs:2174:5
   4: core::option::Option<T>::unwrap
             at /Users/neilconway/.rustup/toolchains/1.92.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/option.rs:1015:21
   5: datafusion_functions::datetime::date_bin::to_utc_date_time
             at ./datafusion/functions/src/datetime/date_bin.rs:380:42
   6: datafusion_functions::datetime::date_bin::date_bin_months_interval
             at ./datafusion/functions/src/datetime/date_bin.rs:346:23
   7: datafusion_functions::datetime::date_bin::date_bin_impl::stride_map_fn::{{closure}}
             at ./datafusion/functions/src/datetime/date_bin.rs:557:23
[...]

Expected behavior

No response

Additional context

No response

Activity

  1. added theissue type on Feb 8, 2026
  2. iampratap7997-dot commented on Feb 8, 2026

    @iampratap7997-dot
    Contributor

    Hi, I’d like to work on this issue.
    Please let me know if it is still available .

    Thanks.

  3. neilconway commented on Feb 8, 2026

    @neilconway
    ContributorAuthor

    Hi, I’d like to work on this issue.
    Please let me know if it is still available .

    Thanks.

    @iampratap7997-dot It is still available, go for it!

  4. mishop-15 commented on Feb 8, 2026

    @mishop-15
    Contributor

    @neilconway I've opened PR #20221 to fix this issue - both queries now return NULL instead of panicking.

  5. iampratap7997-dot commented on Feb 8, 2026

    @iampratap7997-dot
    Contributor

    Thanks for the PR! I was assigned to this issue.
    Let me know if you’d like me to help address the failing checks or follow-up changes.

  6. added a commit that references this issue on Feb 24, 2026
    17d770d
  7. added a commit that references this issue on Mar 24, 2026
    b88f076
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions