BUG: jsonpath .split_part() bypasses lax-mode error suppression - Mailing list pgsql-hackers

From SATYANARAYANA NARLAPURAM
Subject BUG: jsonpath .split_part() bypasses lax-mode error suppression
Date
Msg-id CAHg+QDfdUG+6OJ5kSxmVim-UJkrtffWByLf4oftxwG7_ySYsDA@mail.gmail.com
Whole thread
Responses Re: BUG: jsonpath .split_part() bypasses lax-mode error suppression
List pgsql-hackers
Hi hackers,

The jsonpath string method  .split_part() bypasses lax-mode error suppression.
This is because executeStringInternalMethod() uses DirectFunctionCall1(numeric_int4, ...)
to convert the field number from numeric to int4. This throws ereport(ERROR) directly, 
bypassing the jspThrowErrors(cxt) / RETURN_ERROR mechanism that other methods 
like .double() use correctly.

Reproduction:
-- These should return NULL in lax mode, but throw hard ERRORs:
SELECT '"hello-world"'::jsonb @? '$.split_part("-", 99999999999)';
SELECT '"hello-world"'::jsonb @? '$.split_part("-", 0)';
ERROR:  integer out of range
ERROR:  field position must not be zero


Fix by replacing the bare DirectFunctionCall with numeric_int4_safe()
using ErrorSaveContext to catch overflow, and adding an explicit field==0
check, both gated behind RETURN_ERROR so errors are properly suppressed
in lax/silent mode while still raised in strict/non-silent mode.

Thanks,
Satya
Attachment

pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: eliminate xl_heap_visible to reduce WAL (and eventually set VM on-access)
Next
From: Andres Freund
Date:
Subject: Re: eliminate xl_heap_visible to reduce WAL (and eventually set VM on-access)