pgsql: Fix oversights in array manipulation.

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Fix oversights in array manipulation.
Дата
Msg-id E1pgUMl-005Vxe-P2@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Fix oversights in array manipulation.

The nested-arrays code path in ExecEvalArrayExpr() used palloc to
allocate the result array, whereas every other array-creating function
has used palloc0 since 18c0b4ecc.  This mostly works, but unused bits
past the end of the nulls bitmap may end up undefined.  That causes
valgrind complaints with -DWRITE_READ_PARSE_PLAN_TREES, and could
cause planner misbehavior as cited in 18c0b4ecc.  There seems no very
good reason why we should strive to avoid palloc0 in just this one case,
so fix it the easy way with s/palloc/palloc0/.

While looking at that I noted that we also failed to check for overflow
of "nbytes" and "nitems" while summing the sizes of the sub-arrays,
potentially allowing a crash due to undersized output allocation.
For "nbytes", follow the policy used by other array-munging code of
checking for overflow after each addition.  (As elsewhere, the last
addition of the array's overhead space doesn't need an extra check,
since palloc itself will catch a value between 1Gb and 2Gb.)
For "nitems", there's no very good reason to sum the inputs at all,
since we can perfectly well use ArrayGetNItems' result instead of
ignoring it.

Per discussion of this bug, also remove redundant zeroing of the
nulls bitmap in array_set_element and array_set_slice.

Patch by Alexander Lakhin and myself, per bug #17858 from Alexander
Lakhin; thanks also to Richard Guo.  These bugs are a dozen years old,
so back-patch to all supported branches.

Discussion: https://postgr.es/m/17858-8fd287fd3663d051@postgresql.org

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/11213d44663e71807ec55e31f506983f67ae338f

Modified Files
--------------
src/backend/executor/execExprInterp.c | 13 +++++++++----
src/backend/utils/adt/arrayfuncs.c    |  6 ++----
2 files changed, 11 insertions(+), 8 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Tomas Vondra
Дата:
Сообщение: Re: pgsql: Fix netmask handling in inet_minmax_multi_ops
Следующее
От: Tom Lane
Дата:
Сообщение: Re: pgsql: Fix netmask handling in inet_minmax_multi_ops