summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorDean Rasheed <dean.a.rasheed@gmail.com>2023-11-18 14:47:04 +0000
committerDean Rasheed <dean.a.rasheed@gmail.com>2023-11-18 14:47:04 +0000
commit2851aa7d1fc3bd3dfac00ff2250a7e029ed6499f (patch)
treebfb109ec2b8ff01774a6ec32bbe895d91ea22532 /src/test
parentff772853d02e274684567620fba56dd1f10f2489 (diff)
Guard against overflow in interval_mul() and interval_div().
Commits 146604ec43 and a898b409f6 added overflow checks to interval_mul(), but not to interval_div(), which contains almost identical code, and so is susceptible to the same kinds of overflows. In addition, those checks did not catch all possible overflow conditions. Add additional checks to the "cascade down" code in interval_mul(), and copy all the overflow checks over to the corresponding code in interval_div(), so that they both generate "interval out of range" errors, rather than returning bogus results. Given that these errors are relatively easy to hit, back-patch to all supported branches. Per bug #18200 from Alexander Lakhin, and subsequent investigation. Discussion: https://postgr.es/m/18200-5ea288c7b2d504b1%40postgresql.org
Diffstat (limited to 'src/test')
-rw-r--r--src/test/regress/expected/interval.out13
-rw-r--r--src/test/regress/sql/interval.sql8
2 files changed, 21 insertions, 0 deletions
diff --git a/src/test/regress/expected/interval.out b/src/test/regress/expected/interval.out
index 5350abf1518..f96eadd6caa 100644
--- a/src/test/regress/expected/interval.out
+++ b/src/test/regress/expected/interval.out
@@ -357,6 +357,19 @@ SELECT * FROM INTERVAL_TBL;
@ 5 mons 12 hours
(10 rows)
+-- multiplication and division overflow test cases
+SELECT '3000000 months'::interval * 1000;
+ERROR: interval out of range
+SELECT '3000000 months'::interval / 0.001;
+ERROR: interval out of range
+SELECT '3000000 days'::interval * 1000;
+ERROR: interval out of range
+SELECT '3000000 days'::interval / 0.001;
+ERROR: interval out of range
+SELECT '1 month 2146410 days'::interval * 1000.5002;
+ERROR: interval out of range
+SELECT '4611686018427387904 usec'::interval / 0.1;
+ERROR: interval out of range
-- test avg(interval), which is somewhat fragile since people have been
-- known to change the allowed input syntax for type interval without
-- updating pg_aggregate.agginitval
diff --git a/src/test/regress/sql/interval.sql b/src/test/regress/sql/interval.sql
index 5b4944c2aa5..2a3dd0cfdcb 100644
--- a/src/test/regress/sql/interval.sql
+++ b/src/test/regress/sql/interval.sql
@@ -129,6 +129,14 @@ SET IntervalStyle to postgres_verbose;
SELECT * FROM INTERVAL_TBL;
+-- multiplication and division overflow test cases
+SELECT '3000000 months'::interval * 1000;
+SELECT '3000000 months'::interval / 0.001;
+SELECT '3000000 days'::interval * 1000;
+SELECT '3000000 days'::interval / 0.001;
+SELECT '1 month 2146410 days'::interval * 1000.5002;
+SELECT '4611686018427387904 usec'::interval / 0.1;
+
-- test avg(interval), which is somewhat fragile since people have been
-- known to change the allowed input syntax for type interval without
-- updating pg_aggregate.agginitval