Skip to content

BUG: prevent overflow in npy_datetimestruct_to_datetime #55111

Open
@WillAyd

Description

@WillAyd

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

We have a lot of multiplication in npy_datetimestruct_to_datetime that can overflow:

npy_datetime npy_datetimestruct_to_datetime(NPY_DATETIMEUNIT base,

UBSAN detects this from running test_sql.py (first error only shown):

/pandas/_libs/src/vendored/numpy/datetime/np_datetime.c:359:33: runtime error: signed integer overflow: 253370764800000000 * 1000 cannot be represented in type 'long int'

What will be tricky about this function is it has an integral return value, where all values are technically valid. Ideally we have some way to avoid the overflow and signal an error via CPython

Issue Description

see above

Expected Behavior

see above

Installed Versions

main

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDatetimeDatetime data dtypeInternalsRelated to non-user accessible pandas implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions