summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorNathan Bossart <nathan@postgresql.org>2024-07-23 21:59:02 -0500
committerNathan Bossart <nathan@postgresql.org>2024-07-23 21:59:02 -0500
commit657e54a05859d51e0afb6e44557b5e8622ecd1fe (patch)
treec436647ced525977e85465d185d88d39e18cda71 /src/test
parent165ea79a60774a0e287bfc5dc07363194c6d58df (diff)
Detect integer overflow in array_set_slice().
When provided an empty initial array, array_set_slice() fails to check for overflow when computing the new array's dimensions. While such overflows are ordinarily caught by ArrayGetNItems(), commands with the following form are accepted: INSERT INTO t (i[-2147483648:2147483647]) VALUES ('{}'); To fix, perform the hazardous computations using overflow-detecting arithmetic routines. As with commit 18b585155a, the added test cases generate errors that include a platform-dependent value, so we again use psql's VERBOSITY parameter to suppress printing the message text. Reported-by: Alexander Lakhin Author: Joseph Koshakow Reviewed-by: Jian He Discussion: https://postgr.es/m/31ad2cd1-db94-bdb3-f91a-65ffdb4bef95%40gmail.com Backpatch-through: 12
Diffstat (limited to 'src/test')
-rw-r--r--src/test/regress/expected/arrays.out4
-rw-r--r--src/test/regress/sql/arrays.sql2
2 files changed, 6 insertions, 0 deletions
diff --git a/src/test/regress/expected/arrays.out b/src/test/regress/expected/arrays.out
index 23404982f71..a6d81fd5f92 100644
--- a/src/test/regress/expected/arrays.out
+++ b/src/test/regress/expected/arrays.out
@@ -1427,6 +1427,10 @@ update arr_pk_tbl set f1[2147483647] = 42 where pk = 10;
ERROR: 54000
update arr_pk_tbl set f1[2147483646:2147483647] = array[4,2] where pk = 10;
ERROR: 54000
+insert into arr_pk_tbl(pk, f1[0:2147483647]) values (2, '{}');
+ERROR: 54000
+insert into arr_pk_tbl(pk, f1[-2147483648:2147483647]) values (2, '{}');
+ERROR: 54000
-- also exercise the expanded-array case
do $$ declare a int[];
begin
diff --git a/src/test/regress/sql/arrays.sql b/src/test/regress/sql/arrays.sql
index 50aa539fdc1..47058dfde50 100644
--- a/src/test/regress/sql/arrays.sql
+++ b/src/test/regress/sql/arrays.sql
@@ -447,6 +447,8 @@ reset enable_bitmapscan;
insert into arr_pk_tbl values(10, '[-2147483648:-2147483647]={1,2}');
update arr_pk_tbl set f1[2147483647] = 42 where pk = 10;
update arr_pk_tbl set f1[2147483646:2147483647] = array[4,2] where pk = 10;
+insert into arr_pk_tbl(pk, f1[0:2147483647]) values (2, '{}');
+insert into arr_pk_tbl(pk, f1[-2147483648:2147483647]) values (2, '{}');
-- also exercise the expanded-array case
do $$ declare a int[];