pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Handle zero-length sublist correctly in Python -> SQL array conv
Date: Fri, 28 Apr 2023 16:24:47 +0000
Message-ID: <E1psQtq-005MET-CZ@gemulon.postgresql.org> (raw)

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

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/a1d9aacc4128302129349cb1c86c7807f1555901

Modified Files
--------------
src/pl/plpython/expected/plpython_types.out   |  9 +++++++++
src/pl/plpython/expected/plpython_types_3.out |  9 +++++++++
src/pl/plpython/plpy_typeio.c                 | 23 +++++++----------------
src/pl/plpython/sql/plpython_types.sql        |  7 +++++++
4 files changed, 32 insertions(+), 16 deletions(-)



view thread (6+ messages)  latest in thread

Message-ID: <E1psQtq-005MET-CZ@gemulon.postgresql.org>
Permalink:  ../E1psQtq-005MET-CZ@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1psQtq-005MET-CZ@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Handle zero-length sublist correctly in Python -> SQL array conv
  In-Reply-To: <E1psQtq-005MET-CZ@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox