Detect integer overflow in array_set_slice().
authorNathan Bossart <[email protected]>
Wed, 24 Jul 2024 02:59:02 +0000 (21:59 -0500)
committerNathan Bossart <[email protected]>
Wed, 24 Jul 2024 02:59:02 +0000 (21:59 -0500)
commit878e8c6be7ab2523b3dcbe238578e95162f521e9
treef0a7294331f3d9d6bcd5ba60023a9a5ca3c08eb7
parent77b116724c7545fb610e0f7287d3fbff35ffea22
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
src/backend/utils/adt/arrayfuncs.c
src/test/regress/expected/arrays.out
src/test/regress/sql/arrays.sql