mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Fix integer-overflow edge case detection in interval_mul and pgbench.
This patch adopts the overflow check logic introduced by commitcbdb8b4c0
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 thatcbdb8b4c0
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:
@ -232,6 +232,9 @@ INSERT INTO INTERVAL_TBL_OF (f1) VALUES ('-2147483648 years');
|
||||
ERROR: interval out of range
|
||||
LINE 1: INSERT INTO INTERVAL_TBL_OF (f1) VALUES ('-2147483648 years'...
|
||||
^
|
||||
-- Test edge-case overflow detection in interval multiplication
|
||||
select extract(epoch from '256 microseconds'::interval * (2^55)::float8);
|
||||
ERROR: interval out of range
|
||||
SELECT r1.*, r2.*
|
||||
FROM INTERVAL_TBL_OF r1, INTERVAL_TBL_OF r2
|
||||
WHERE r1.f1 > r2.f1
|
||||
|
@ -73,6 +73,9 @@ INSERT INTO INTERVAL_TBL_OF (f1) VALUES ('-2147483649 days');
|
||||
INSERT INTO INTERVAL_TBL_OF (f1) VALUES ('2147483647 years');
|
||||
INSERT INTO INTERVAL_TBL_OF (f1) VALUES ('-2147483648 years');
|
||||
|
||||
-- Test edge-case overflow detection in interval multiplication
|
||||
select extract(epoch from '256 microseconds'::interval * (2^55)::float8);
|
||||
|
||||
SELECT r1.*, r2.*
|
||||
FROM INTERVAL_TBL_OF r1, INTERVAL_TBL_OF r2
|
||||
WHERE r1.f1 > r2.f1
|
||||
|
Reference in New Issue
Block a user