Skip to content

[C++][Python] round_temporal/floor_temporal/ceil_temporal crash the process with multiple=0 #55921

In review

Description

@arunsahabytes

Describe the bug, including details regarding any error messages, version, and platform.

round_temporal, floor_temporal and ceil_temporal don't validate multiple. With multiple=0 the whole Python process crashes with an integer division by zero instead of raising an error.

import pyarrow as pa
import pyarrow.compute as pc

arr = pa.array([1000], type=pa.timestamp("ns"))
pc.floor_temporal(arr, multiple=0, unit="second")   # process exits, no Python exception

Same for round_temporal and ceil_temporal. On Windows the exit code is 0xC0000094 (STATUS_INTEGER_DIVIDE_BY_ZERO).

A negative multiple doesn't crash but gives wrong results, e.g. ceil_temporal returns a time before the input:

import datetime as dt
a = pa.array([dt.datetime(2024, 1, 1, 10, 7, 30)], type=pa.timestamp("s"))

pc.ceil_temporal(a, multiple=15, unit="minute")    # 2024-01-01 10:15:00
pc.ceil_temporal(a, multiple=-15, unit="minute")   # 2024-01-01 09:45:00
pc.round_temporal(a, multiple=-15, unit="minute")  # 2024-01-01 09:45:00

For comparison, round_to_multiple already checks this:

pc.round_to_multiple(pa.array([5.0]), multiple=0)
# ArrowInvalid: Rounding multiple must be positive

Expected: ArrowInvalid for multiple <= 0 in all three temporal functions. I checked cpp/src/arrow/compute/kernels/scalar_temporal_unary.cc on main and didn't find a check on options.multiple, so an early Status::Invalid("Rounding multiple must be positive") in the kernel (or in RoundTemporalOptions validation) would match round_to_multiple.

pyarrow 26.0.1 (latest on PyPI), Python 3.12, Windows 11.

Component(s)

C++, Python

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions