]> git.ipfire.org Git - thirdparty/postgresql.git/commit
jsonb_plperl, jsonb_plpython: Fix unguarded recursion and loops.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 17 Jun 2026 15:04:41 +0000 (11:04 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 17 Jun 2026 15:04:41 +0000 (11:04 -0400)
commitda82fbb8f9a3b1e46b55d5975ef59113cd3a59a6
treea8b7fe58e225c127650c51f0b19a5a5053e16f6a
parentd2cea63065b3684d2d1eba4c3f4dea68bf1b373c
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@tigerdata.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAJ7c6TPbjkzUk4qJ5dHvDNEz0hBuFue3A-XWz_=897z+BC+z8A@mail.gmail.com
Backpatch-through: 14
contrib/jsonb_plperl/jsonb_plperl.c
contrib/jsonb_plpython/jsonb_plpython.c