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: Make plperl's handling of Perl arrays safer and more consistent.
Date: Mon, 17 Aug 2026 19:06:17 +0000
Message-ID: <E1ww2f2-00000000xFE-2ygs@gemulon.postgresql.org> (raw)

Make plperl's handling of Perl arrays safer and more consistent.

plperl_func_handler()'s stanza for handling an arrayref result in
a SETOF function could loop forever (or at least till OOM) when
given a tied array, since av_fetch won't necessarily ever return
a null pointer in that case.  Be consistent with the other places
where we traverse a perl array: call av_len() once and use len+1
as the loop limit, silently ignoring any null pointers we get back
from that range of subscripts.

But actually, Perl's preferred locution for this seems to be to
use av_count() not av_len()+1.  av_count() seems better since
there's less risk of forgetting to add 1.  Also, both of those
functions return Size_t (or SSize_t) not int, creating at least
a theoretical overflow hazard.  While we're modernizing this,
let's use the correct variable type where we can, and include an
overflow check where we can't.

Reported-by: Claude Code (via Noah Misch)
Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Andrey Rachitskiy <pl0h0yp1@gmail.com>
Discussion: https://postgr.es/m/569769.1786901901@sss.pgh.pa.us
Backpatch-through: 14

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/131444cd167afd135768b5d1605caf89fb25e4e2

Modified Files
--------------
contrib/jsonb_plperl/jsonb_plperl.c |  5 ++---
src/pl/plperl/plperl.c              | 41 ++++++++++++++++++++++++++++---------
2 files changed, 33 insertions(+), 13 deletions(-)



view thread (7+ messages)  latest in thread

Message-ID: <E1ww2f2-00000000xFE-2ygs@gemulon.postgresql.org>
Permalink:  ../E1ww2f2-00000000xFE-2ygs@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1ww2f2-00000000xFE-2ygs@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: Make plperl's handling of Perl arrays safer and more consistent.
  In-Reply-To: <E1ww2f2-00000000xFE-2ygs@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