diff options
author | Alexander Korotkov <akorotkov@postgresql.org> | 2020-07-11 03:21:00 +0300 |
---|---|---|
committer | Alexander Korotkov <akorotkov@postgresql.org> | 2020-07-11 03:21:00 +0300 |
commit | df646509f371069c65f84309eb5749642e8650b3 (patch) | |
tree | 8fc801b1d4906aeef99e0952a43455da1671d262 /src/backend/utils/adt/jsonpath_exec.c | |
parent | 0657181167467ec5cfb5a28aacf47ca02f5f4588 (diff) | |
download | postgresql-df646509f371069c65f84309eb5749642e8650b3.tar.gz postgresql-df646509f371069c65f84309eb5749642e8650b3.zip |
Forbid numeric NaN in jsonpath
SQL standard doesn't define numeric Inf or NaN values. It appears even more
ridiculous to support then in jsonpath assuming JSON doesn't support these
values as well. This commit forbids returning NaN from .double(), which was
previously allowed. NaN can't be result of inner-jsonpath computation over
non-NaNs. So, we can not expect NaN in the jsonpath output.
Reported-by: Tom Lane
Discussion: https://postgr.es/m/203949.1591879542%40sss.pgh.pa.us
Author: Alexander Korotkov
Reviewed-by: Tom Lane
Backpatch-through: 12
Diffstat (limited to 'src/backend/utils/adt/jsonpath_exec.c')
-rw-r--r-- | src/backend/utils/adt/jsonpath_exec.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/backend/utils/adt/jsonpath_exec.c b/src/backend/utils/adt/jsonpath_exec.c index 25ec3dcd802..f146767bfc3 100644 --- a/src/backend/utils/adt/jsonpath_exec.c +++ b/src/backend/utils/adt/jsonpath_exec.c @@ -1044,15 +1044,16 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, { char *tmp = DatumGetCString(DirectFunctionCall1(numeric_out, NumericGetDatum(jb->val.numeric))); + double val; bool have_error = false; - (void) float8in_internal_opt_error(tmp, - NULL, - "double precision", - tmp, - &have_error); + val = float8in_internal_opt_error(tmp, + NULL, + "double precision", + tmp, + &have_error); - if (have_error) + if (have_error || isinf(val) || isnan(val)) RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM), errmsg("numeric argument of jsonpath item method .%s() is out of range for type double precision", @@ -1073,7 +1074,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, tmp, &have_error); - if (have_error || isinf(val)) + if (have_error || isinf(val) || isnan(val)) RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM), errmsg("string argument of jsonpath item method .%s() is not a valid representation of a double precision number", |