Fix integer overflow in array_agg(), when the array grows too large

Heikki Linnakangas <heikki.linnakangas@iki.fi>

Commit: 67dd6243dc95df560ff3c31ed5b6e9474d98c4c3
Author: Heikki Linnakangas <heikki.linnakangas@iki.fi>
Committer: Noah Misch <noah@leadboat.com>
Date: 2026-05-11T12:13:48Z
Releases: 18.4
Fix integer overflow in array_agg(), when the array grows too large

If you accumulate many arrays full of NULLs, you could overflow
'nitems', before reaching the MaxAllocSize limit on the allocations.
Add an explicit check that the number of items doesn't grow too large.
With more than MaxArraySize items, getting the final result with
makeArrayResultArr() would fail anyway, so better to error out early.

Reported-by: Xint Code
Author: Heikki Linnakangas <heikki.linnakangas@iki.fi>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Backpatch-through: 14
Security: CVE-2026-6473

Files

PathChange+/−
src/backend/utils/adt/arrayfuncs.c modified +10 −3