pgsql: jsonb_plperl, jsonb_plpython: Fix unguarded recursion and loops.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: jsonb_plperl, jsonb_plpython: Fix unguarded recursion and loops.
Date: 2026-06-17 15:04:56
Message-ID: E1wZrp2-000jb5-0T@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

jsonb_plperl, jsonb_plpython: Fix unguarded recursion and loops.

Add check_stack_depth() to Jsonb_to_SV, SV_to_JsonbValue,
PLyObject_FromJsonbContainer, and PLyObject_ToJsonbValue. Without
this, deeply nested JSONB values can crash the backend with SIGSEGV
instead of raising a proper error.

Also add CHECK_FOR_INTERRUPTS() to the while loop in SV_to_JsonbValue
that dereferences chains of Perl references, so that a circular
reference (e.g. $x = \$x) can be cancelled by the user instead of
spinning indefinitely. (We looked at detecting such circular
references, but it seems more trouble than it's worth.)

Author: Aleksander Alekseev <aleksander(at)tigerdata(dot)com>
Reviewed-by: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Discussion: https://postgr.es/m/CAJ7c6TPbjkzUk4qJ5dHvDNEz0hBuFue3A-XWz_=897z+BC+z8A@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_15_STABLE

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

Modified Files
--------------
contrib/jsonb_plperl/jsonb_plperl.c | 15 +++++++++++++++
contrib/jsonb_plpython/jsonb_plpython.c | 7 +++++++
2 files changed, 22 insertions(+)

Browse pgsql-committers by date

  From Date Subject
Next Message Jacob Champion 2026-06-17 20:55:58 pgsql: libpq-oauth: Print libcurl version with OAUTHDEBUG_UNSAFE_TRACE
Previous Message Nathan Bossart 2026-06-17 14:19:05 pgsql: vacuumdb: Fix --missing-stats-only for partitioned indexes.