From e348e7ae5727a6da8678036d748e5c5af7deb6c9 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Mon, 30 Apr 2018 12:28:45 -0400 Subject: Prevent infinity and NaN in jsonb/plperl transform MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit jsonb uses numeric internally, and numeric can store NaN, but that is not allowed by jsonb on input, so we shouldn't store it. Also prevent infinity to get a consistent error message. (numeric input would reject infinity anyway.) Reported-by: Dagfinn Ilmari Mannsåker Reviewed-by: Tom Lane --- contrib/jsonb_plperl/sql/jsonb_plperl.sql | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'contrib/jsonb_plperl/sql/jsonb_plperl.sql') diff --git a/contrib/jsonb_plperl/sql/jsonb_plperl.sql b/contrib/jsonb_plperl/sql/jsonb_plperl.sql index 8b0a8764afa..5f94a4c51ae 100644 --- a/contrib/jsonb_plperl/sql/jsonb_plperl.sql +++ b/contrib/jsonb_plperl/sql/jsonb_plperl.sql @@ -34,6 +34,28 @@ $$; SELECT testSVToJsonb(); +CREATE FUNCTION testInf() RETURNS jsonb +LANGUAGE plperl +TRANSFORM FOR TYPE jsonb +AS $$ +$val = 0 + 'Inf'; +return $val; +$$; + +SELECT testInf(); + + +CREATE FUNCTION testNaN() RETURNS jsonb +LANGUAGE plperl +TRANSFORM FOR TYPE jsonb +AS $$ +$val = 0 + 'NaN'; +return $val; +$$; + +SELECT testNaN(); + + -- this revealed a bug in the original implementation CREATE FUNCTION testRegexpResultToJsonb() RETURNS jsonb LANGUAGE plperl -- cgit v1.2.3