]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Handle zero-length sublist correctly in Python -> SQL array conversion.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 28 Apr 2023 16:24:29 +0000 (12:24 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 28 Apr 2023 16:24:29 +0000 (12:24 -0400)
commit7dcd9998c19d7e1a86bc0d76167e429455e3db5f
tree8492e716452f54ae3976a2c85e79b829df1d619b
parent7e95a33b42e76d34053bfc9c2845d43753a2e7b3
Handle zero-length sublist correctly in Python -> SQL array conversion.

If PLySequence_ToArray came across a zero-length sublist, it'd compute
the overall array size as zero, possibly leading to a memory clobber.
(This would likely qualify as a security bug, were it not that plpython
is an untrusted language already.)

I think there are other corner-case issues in this code as well, notably
that the error messages don't match the core code and for some ranges
of array sizes you'd get "invalid memory alloc request size" rather than
the intended message about array size.

Really this code has no business doing its own array size calculation
at all, so remove the faulty code in favor of using ArrayGetNItems().

Per bug #17912 from Alexander Lakhin.  Bug seems to have come in with
commit 94aceed31, so back-patch to all supported branches.

Discussion: https://postgr.es/m/17912-82ceed78731d9cdc@postgresql.org
src/pl/plpython/expected/plpython_types.out
src/pl/plpython/expected/plpython_types_3.out
src/pl/plpython/plpy_typeio.c
src/pl/plpython/sql/plpython_types.sql