Re: BUG #19670: Silent Integer Overflow in time_pl_interval() Returns Wrong Time Value - Mailing list pgsql-bugs

From Rahul Yadav
Subject Re: BUG #19670: Silent Integer Overflow in time_pl_interval() Returns Wrong Time Value
Date
Msg-id CAJJjRRe0fUFsh4ocp4bBui=Jd+_t4cwYAs53kYzteRGmMm_SBw@mail.gmail.com
Whole thread
Responses Re: BUG #19670: Silent Integer Overflow in time_pl_interval() Returns Wrong Time Value
List pgsql-bugs
Hi,

I can reproduce this on master. time_pl_interval() adds the
interval's time field to the time value before reducing the result
modulo one day, so a large enough interval overflows int64.
time_mi_interval() and the two timetz variants have the same problem.

Since the result wraps around at midnight anyway, only the interval's
time field modulo one day matters. The attached patch reduces it
first, so the intermediate result always fits in an int64; results
for intervals that didn't overflow are unchanged. It also adds
regression tests for the largest and smallest interval time values,
which fail without the fix.

The same arithmetic exists in all supported branches, so I think this
should be back-patched.

Regards,
Rahul Yadav

Attachment

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #19722: Window PARTITION BY numeric treats equal values with different scales as separate partitions
Next
From: jian he
Date:
Subject: Re: BUG #19621: Unexpected results of JSON_VALUE with DEFAULT ON EMPTY