Re: [PATCH] Fix segmentation fault and infinite loop in jsonb_{plperl,plpython}

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Aleksander Alekseev <aleksander@tigerdata.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2026-06-16T21:10:16Z
Lists: pgsql-hackers
Aleksander Alekseev <aleksander@tigerdata.com> writes:
>> We could instead add a CHECK_FOR_INTERRUPTS, so that you can at
>> least break out of the infinite loop.  I'm not sure if the case
>> is worth more effort than that.

> Alternatively I could implement a check for the loops, if you feel
> like this is worth the effort.

I thought about that, but I'm not sure how to build a bulletproof
check at reasonable (ie, near zero) cost.  We could detect the example
case where an object refers directly to itself, by noticing that "in"
doesn't change in one iteration.  But I'm pretty sure it's possible to
build reference loops involving two or more Perl objects, and those
would fool such a check.

			regards, tom lane



Commits

  1. hstore_plperl: Add CHECK_FOR_INTERRUPTS() in reference-unwinding loop.

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