Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xTFQW-00000000DBf-070w for pgsql-bugs@arkaria.postgresql.org; Tue, 17 Nov 2026 09:24:32 +0000 Received: from localhost ([127.0.0.1]:51124 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xTFQV-00000004eTj-1NOX for pgsql-bugs@arkaria.postgresql.org; Tue, 17 Nov 2026 09:24:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]:35276) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xTBMW-00000002naR-0wEo for pgsql-bugs@lists.postgresql.org; Tue, 17 Nov 2026 05:04:08 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xTBMT-000000007AQ-1mY6 for pgsql-bugs@lists.postgresql.org; Tue, 17 Nov 2026 05:04:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=mh4rpnLaUsAVh5vFNmWC8OL6J1r1bA7ABzad5dG+fSI=; b=iDC0NXfxWmMPRi9AtTC/FwGxE4 22dPGF/gllfAyOiRnrbP8ypCqVAlULARzhHS/5Jn23cS8XI9s9Ov2wceiYw+tVwBIOJBTBtF0E0nQ hduoCEjXil5iGQTVGwLRvedIPR/nV/tf3o9jvQkGoFbRH+Hgw9KYe0vubGlBG01Y6zR0AX2jqKIHw cmQjqeSd3PeXr0KdtTqv9jkmTxztriHs8TfxlmvwczJ2PTfnCbotAVWAYdwbiiTTkv9iyaC+1VozS 2VmkhRJJ9MGdlita8aD5bJcPyTw55mu7WMmqIA6NTSV5kHrz48Rq+gPDOkwXO40hMbQ5phtVB/X54 Vble05xQ==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xTBMR-00000000Gb8-29Es for pgsql-bugs@lists.postgresql.org; Tue, 17 Nov 2026 05:04:04 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xTBMQ-00000000fq5-17bF for pgsql-bugs@lists.postgresql.org; Tue, 17 Nov 2026 05:04:02 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19910: json(b)_to_tsvector() nested array filter gives internal error XX000 "unexpected end of flag array" To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: hackerzheng666@gmail.com Reply-To: hackerzheng666@gmail.com, pgsql-bugs@lists.postgresql.org Date: Tue, 17 Nov 2026 05:03:22 +0000 Message-ID: <19910-24199f8af1474753@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19910 Logged by: Zheng Hacker Email address: hackerzheng666@gmail.com PostgreSQL version: 19rc2 Operating system: Linux x86_64 (Ubuntu 22.04), clang 14, cassert Description: =20 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 =3D JsonbIteratorNext(&it, &v, false)) =3D=3D WJB_ELEM) { if (v.type !=3D jbvString) ereport(ERROR, ... "flag array element is not a string" ...); ... } /* expect end of array now */ if (type !=3D 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).