Hi Tom, > Pushed with some comments added.
Thanks for applying the patch. I looked around and found the same bug in hstore_plperl: ``` =# CREATE EXTENSION IF NOT EXISTS hstore_plperl CASCADE; CREATE EXTENSION =# CREATE OR REPLACE FUNCTION hstore_circular() RETURNS hstore LANGUAGE plperl TRANSFORM FOR TYPE hstore AS $$ my $x; $x = \$x; return $x; $$; CREATE FUNCTION =# SELECT hstore_circular(); ^CCancel request sent ^CCancel request sent ^CCancel request sent ``` >From what I can tell this is the last issue like this. Here is the patch. Would you like to merge it as well or will it be better to start a new thread for visibility? -- Best regards, Aleksander Alekseev
From 43c7cc6353ca9700471ca41c8e4aa1db4aee58c1 Mon Sep 17 00:00:00 2001 From: Aleksander Alekseev <[email protected]> Date: Thu, 18 Jun 2026 14:41:33 +0300 Subject: [PATCH v1] hstore_plperl: Add CHECK_FOR_INTERRUPTS() in reference-unwinding loop plperl_to_hstore() uses a while loop to dereference chains of Perl references before processing the underlying hash value. This loop had no way to be interrupted, so a circular reference chain (e.g. $x = \$x) would cause the backend to spin indefinitely without any possibility of cancellation via Ctrl+C. Add CHECK_FOR_INTERRUPTS() inside the loop so that a query involving a circular Perl reference can be cancelled by the user. This is a follow-up to da82fbb8f9, which fixed the same issue in SV_to_JsonbValue() in jsonb_plperl. Author: Aleksander Alekseev <[email protected]> Reviewed-by: Tom Lane <[email protected]> Discussion: https://postgr.es/m/CAJ7c6TPbjkzUk4qJ5dHvDNEz0hBuFue3A-XWz_=897z+bc+...@mail.gmail.com Backpatch-through: 14 --- contrib/hstore_plperl/hstore_plperl.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/contrib/hstore_plperl/hstore_plperl.c b/contrib/hstore_plperl/hstore_plperl.c index 996b46b148d..1da6fd228ce 100644 --- a/contrib/hstore_plperl/hstore_plperl.c +++ b/contrib/hstore_plperl/hstore_plperl.c @@ -2,6 +2,7 @@ #include "fmgr.h" #include "hstore/hstore.h" +#include "miscadmin.h" #include "plperl.h" PG_MODULE_MAGIC_EXT( @@ -111,7 +112,10 @@ plperl_to_hstore(PG_FUNCTION_ARGS) /* Dereference references recursively. */ while (SvROK(in)) + { + CHECK_FOR_INTERRUPTS(); in = SvRV(in); + } /* Now we must have a hash. */ if (SvTYPE(in) != SVt_PVHV) -- 2.43.0
