Skip to content

Commit 40f52b1

Browse files
committed
Prevent NaN in jsonb/plpython transform
As in e348e7a for jsonb/plperl, prevent putting a NaN into a jsonb numeric field. Tests for this had been removed in 6278a2a, but in case they are ever resurrected: This would change the output of the test1nan() function to an error.
1 parent 0996e4b commit 40f52b1

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

contrib/jsonb_plpython/jsonb_plpython.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "plpy_typeio.h"
66
#include "utils/jsonb.h"
77
#include "utils/fmgrprotos.h"
8+
#include "utils/numeric.h"
89

910
PG_MODULE_MAGIC;
1011

@@ -343,6 +344,16 @@ PLyNumber_ToJsonbValue(PyObject *obj, JsonbValue *jbvNum)
343344

344345
pfree(str);
345346

347+
/*
348+
* jsonb doesn't allow NaN (per JSON specification), so we have to prevent
349+
* it here explicitly. (Infinity is also not allowed in jsonb, but
350+
* numeric_in above already catches that.)
351+
*/
352+
if (numeric_is_nan(num))
353+
ereport(ERROR,
354+
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
355+
(errmsg("cannot convert NaN to jsonb"))));
356+
346357
jbvNum->type = jbvNumeric;
347358
jbvNum->val.numeric = num;
348359

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy