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

Aleksander Alekseev <aleksander@tigerdata.com>

From: Aleksander Alekseev <aleksander@tigerdata.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2026-06-17T11:07:04Z
Lists: pgsql-hackers

Attachments

Hi Tom,

Thanks for all your great feedback.

> No, it'd be O(N^2) for an N-deep reference chain.  Admittedly,
> realistic use-cases would never have more than a couple of layers of
> indirection.  But this whole exercise is to guard against adversarial
> inputs, I think.  I don't really want to add cycles and complexity to
> make our behavior a bit more friendly in cases that nobody is going
> to get into unless they are trying to break the database.

OK, that's fair enough. Here is the corrected patch.

```
=# SELECT perl_circular();
^CCancel request sent
ERROR:  canceling statement due to user request
CONTEXT:  PL/Perl function "perl_circular"
```

-- 
Best regards,
Aleksander Alekseev

Commits

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

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