1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-22 21:53:06 +03:00

Fix integer-overflow edge case detection in interval_mul and pgbench.

This patch adopts the overflow check logic introduced by commit cbdb8b4c0
into two more places.  interval_mul() failed to notice if it computed a
new microseconds value that was one more than INT64_MAX, and pgbench's
double-to-int64 logic had the same sorts of edge-case problems that
cbdb8b4c0 fixed in the core code.

To make this easier to get right in future, put the guts of the checks
into new macros in c.h, and add commentary about how to use the macros
correctly.

Back-patch to all supported branches, as we did with the previous fix.

Yuya Watari

Discussion: https://postgr.es/m/CAJ2pMkbkkFw2hb9Qb1Zj8d06EhWAQXFLy73St4qWv6aX=vqnjw@mail.gmail.com
This commit is contained in:
Tom Lane
2019-11-07 11:22:52 -05:00
parent b1bebc2cee
commit 84780d4680
6 changed files with 43 additions and 55 deletions

View File

@@ -3410,7 +3410,7 @@ interval_mul(PG_FUNCTION_ARGS)
result->day += (int32) month_remainder_days;
#ifdef HAVE_INT64_TIMESTAMP
result_double = rint(span->time * factor + sec_remainder * USECS_PER_SEC);
if (result_double > PG_INT64_MAX || result_double < PG_INT64_MIN)
if (isnan(result_double) || !FLOAT8_FITS_IN_INT64(result_double))
ereport(ERROR,
(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
errmsg("interval out of range")));