In array_position()/array_positions(), beware of empty input array.

Tom Lane <tgl@sss.pgh.pa.us>

Commit: d5de344a50d3fa03fad38fe41cc3443db4143bb5
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date: 2023-05-04T15:48:23Z
Releases: 14.8
In array_position()/array_positions(), beware of empty input array.

These functions incautiously fetched the array's first lower bound
even when the array is zero-dimensional, thus fetching the word
after the allocated array space.  While almost always harmless,
with very bad luck this could result in SIGSEGV.  Fix by adding
an early exit for empty input.

Per bug #17920 from Alexander Lakhin.

Discussion: https://postgr.es/m/17920-f7c228c627b6d02e%40postgresql.org

Files

PathChange+/−
src/backend/utils/adt/array_userfuncs.c modified +12 −4

Discussion