Skip to content

Overflow in interval loading in C module #719

@enapupe

Description

@enapupe

It seems there's a bug within psycopg-binary IntervalLoader implementation, this however can't be reproduced using the python version of IntervalLoader.

To reproduce the issue:

pip install psycopg

import psycopg

conn = psycopg.connect(user='postgres', password='postgres', dbname='postgres')

with conn.cursor() as cur:
    cur.execute("select ('1993534:40:40.447')::interval")
    row=cur.fetchone()
    print(row)

output from the above code: ✅
(datetime.timedelta(days=83063, seconds=81640, microseconds=447000),)

now pip install psycopg-binary and run the code again, it outputs: ❌
(datetime.timedelta(days=-16357, seconds=35048, microseconds=447000),)

It seems regular int is overflowing so long must be used for seconds, here's a rough patch

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions