mirror of
https://github.com/postgres/postgres.git
synced 2025-06-26 12:21:12 +03:00
Detect overflow in timestamp[tz] subtraction.
It's possible to overflow the int64 microseconds field of the output interval when subtracting two timestamps. Detect that instead of silently returning a bogus result. Nick Babadzhanian Discussion: https://postgr.es/m/CABw73Uq2oJ3E+kYvvDuY04EkhhkChim2e-PaghBDjOmgUAMWGw@mail.gmail.com
This commit is contained in:
@ -2713,7 +2713,10 @@ timestamp_mi(PG_FUNCTION_ARGS)
|
||||
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
|
||||
errmsg("cannot subtract infinite timestamps")));
|
||||
|
||||
result->time = dt1 - dt2;
|
||||
if (unlikely(pg_sub_s64_overflow(dt1, dt2, &result->time)))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
|
||||
errmsg("interval out of range")));
|
||||
|
||||
result->month = 0;
|
||||
result->day = 0;
|
||||
|
Reference in New Issue
Block a user