diff --git a/src/pl/plperl/expected/plperl_array.out b/src/pl/plperl/expected/plperl_array.out index bd04a062fb9..03e5629d699 100644 --- a/src/pl/plperl/expected/plperl_array.out +++ b/src/pl/plperl/expected/plperl_array.out @@ -274,3 +274,10 @@ select perl_setof_array('{{1}, {2}, {3}}'); {3} (3 rows) +-- Test a forged PostgreSQL::InServer::ARRAY object lacking the 'array' key +CREATE OR REPLACE FUNCTION perl_forged_array() RETURNS integer[] AS $$ + return bless {}, "PostgreSQL::InServer::ARRAY"; +$$ LANGUAGE plperl; +SELECT perl_forged_array(); +ERROR: could not get array reference from PostgreSQL::InServer::ARRAY object +CONTEXT: PL/Perl function "perl_forged_array" diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c index fe6efdb3740..b3834f71424 100644 --- a/src/pl/plperl/plperl.c +++ b/src/pl/plperl/plperl.c @@ -1151,7 +1151,7 @@ get_perl_array_ref(SV *sv) HV *hv = (HV *) SvRV(sv); SV **sav = hv_fetch_string(hv, "array"); - if (*sav && SvOK(*sav) && SvROK(*sav) && + if (sav && *sav && SvOK(*sav) && SvROK(*sav) && SvTYPE(SvRV(*sav)) == SVt_PVAV) return *sav; diff --git a/src/pl/plperl/sql/plperl_array.sql b/src/pl/plperl/sql/plperl_array.sql index ca63b5db625..cd1d7e34c50 100644 --- a/src/pl/plperl/sql/plperl_array.sql +++ b/src/pl/plperl/sql/plperl_array.sql @@ -206,3 +206,10 @@ create or replace function perl_setof_array(integer[]) returns setof integer[] l $$; select perl_setof_array('{{1}, {2}, {3}}'); + +-- Test a forged PostgreSQL::InServer::ARRAY object lacking the 'array' key +CREATE OR REPLACE FUNCTION perl_forged_array() RETURNS integer[] AS $$ + return bless {}, "PostgreSQL::InServer::ARRAY"; +$$ LANGUAGE plperl; + +SELECT perl_forged_array();