| From: | PG Bug reporting form <noreply(at)postgresql(dot)org> |
|---|---|
| To: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
| Cc: | hackerzheng666(at)gmail(dot)com |
| Subject: | BUG #19910: json(b)_to_tsvector() nested array filter gives internal error XX000 "unexpected end of flag array" |
| Date: | 2026-11-17 05:03:22 |
| Message-ID: | 19910-24199f8af1474753@postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
The following bug has been logged on the website:
Bug reference: 19910
Logged by: Zheng Hacker
Email address: hackerzheng666(at)gmail(dot)com
PostgreSQL version: 19rc2
Operating system: Linux x86_64 (Ubuntu 22.04), clang 14, cassert
Description:
A filter argument that contains a nested array is rejected with an
internal-error message (SQLSTATE XX000, raised by elog) instead of the
invalid_parameter_value error that every other bad filter gets:
select jsonb_to_tsvector('english'::regconfig, '{"a":"b c"}'::jsonb,
'[[1]]'::jsonb);
ERROR: XX000: unexpected end of flag array
LOCATION: parse_jsonb_index_flags, jsonfuncs.c:5643
select json_to_tsvector('english'::regconfig, '{}'::json, '[[1]]'::jsonb);
ERROR: XX000: unexpected end of flag array
For comparison, other invalid filters give a proper error with a hint:
select jsonb_to_tsvector('english'::regconfig, '{"a":"b c"}'::jsonb,
'["nope"]'::jsonb);
ERROR: 22023: wrong flag in flag array: "nope"
HINT: Possible values are: "string", "numeric", "boolean", "key", and
"all".
select jsonb_to_tsvector('english'::regconfig, '{"a":"b c"}'::jsonb,
'{"x":1}'::jsonb);
ERROR: 22023: wrong flag type, only arrays and scalars are allowed
select jsonb_to_tsvector('english'::regconfig, '{"a":"b c"}'::jsonb,
'[1]'::jsonb); -- per the code: "flag array element is not a string"
Cause, from reading src/backend/utils/adt/jsonfuncs.c,
parse_jsonb_index_flags(): the loop
while ((type = JsonbIteratorNext(&it, &v, false)) == WJB_ELEM)
{
if (v.type != jbvString) ereport(ERROR, ... "flag array element is
not a string" ...);
...
}
/* expect end of array now */
if (type != WJB_END_ARRAY)
elog(ERROR, "unexpected end of flag array");
only continues while the iterator returns WJB_ELEM. A nested array element
makes the iterator return WJB_BEGIN_ARRAY, the loop exits, the token is not
WJB_END_ARRAY, and the "cannot happen" elog fires. So user input reaches an
internal-error path. I did not test a patch. Probably the loop should handle
the nested container the same way as a non-string element (report "flag
array element is not a string" with the hint), or the check after the loop
should raise ERRCODE_INVALID_PARAMETER_VALUE.
Found by a systematic call of every SQL-callable function with boundary and
structured arguments on a cassert build; reproduced 6 of 6 times on a fresh
cluster. Severity: low (wrong SQLSTATE and message for invalid input, no
crash).
Tested on git master (20devel, commit
5ffc82103773ea1ab5aa699edc301d4f03de4ce). Master HEAD 7fc2f0423320
(2026-11-16) has the same code in parse_jsonb_index_flags()
(jsonfuncs.c:5643; read from master, not built).
| From | Date | Subject | |
|---|---|---|---|
| Next Message | surya poondla | 2026-11-17 05:36:41 | Re: Two issues with REFRESH MATERIALIZED VIEW CONCURRENTLY |
| Previous Message | PG Bug reporting form | 2026-11-17 05:03:04 | BUG #19909: BRIN redo: BufferIsPinned assert in brin_xlog_insert_update() if index was dropped or truncated |