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 1xDjQB-00000000fu8-22Dr for pgsql-bugs@arkaria.postgresql.org; Mon, 05 Oct 2026 14:12:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xDjQA-0000000Awoj-1ysk for pgsql-bugs@arkaria.postgresql.org; Mon, 05 Oct 2026 14:12:02 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xDEbu-000000043Ah-2ywO for pgsql-bugs@lists.postgresql.org; Sun, 04 Oct 2026 05:18:06 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xDEbt-00000000GSA-0BLf for pgsql-bugs@lists.postgresql.org; Sun, 04 Oct 2026 05:18:05 +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=W4abQVpcKvIVIC+JITS9ZoSe5HN92xWnuovUoaopvc0=; b=2JYVQNm3Ek/XHJ1z1KVhivXbuF /cFno/iQeKp3XiY8YLm4MZiKxDsNdRA0fq4Vr6Yw3OiYAGMSi+tkVfSvEl1gXJsiBP4uwl3OAnaez FfPQboavYrV9ThWE3H6MMv2g4d9JazzVDAwf6GgG7R8ZxxRHq5hf6XqThsDtr8YXgnSrVblFtyWC5 IMwAEf58EUF89fT3zeU97UzVitMz0k1+psxRVmrlBuXztMptITLIz1r4fV7jpo1bKrlKzr44IG6AB 7SRN6fQZn6kQvL2jS41naTSFTEgixCq9tpcovnpvkalvBgazcYKEzYu4cPL5Y0L56jyAWaiY4I17z CW5KYmUA==; 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 1xDEbs-00000000uhQ-3D72 for pgsql-bugs@lists.postgresql.org; Sun, 04 Oct 2026 05:18: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 1xDEbr-00000002S37-2wTh for pgsql-bugs@lists.postgresql.org; Sun, 04 Oct 2026 05:18:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19745: tsquery input: 33 nested "!" raise XX000 via elog(), escaping pg_input_is_valid() To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: kehan5800@gmail.com Reply-To: kehan5800@gmail.com, pgsql-bugs@lists.postgresql.org Date: Sun, 04 Oct 2026 05:17:04 +0000 Message-ID: <19745-39cd7b93a505f9a9@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: 19745 Logged by: Ke Email address: kehan5800@gmail.com PostgreSQL version: 18.6 Operating system: Ubuntu 22.04.2 x86_64 Description: =20 makepol() in src/backend/utils/adt/tsquery.c keeps a fixed operator stack (STACKDEPTH =3D 32, tsquery.c:627), and pushOpStack() reports overflow as an internal error: static void pushOpStack(OperatorElement *stack, int *lenstack, int8 op, int16 distance) { if (*lenstack =3D=3D STACKDEPTH) /* internal error */ elog(ERROR, "tsquery stack too small"); (tsquery.c:638-639). The prefix operator "!" pushes an entry per occurrence, so the condition is reachable from plain user input: SELECT (repeat('!', 32) || 'a')::tsquery; -- ok SELECT (repeat('!', 33) || 'a')::tsquery; ERROR: XX000: tsquery stack too small LOCATION: pushOpStack, tsquery.c:639 SELECT websearch_to_tsquery('simple', repeat('-', 33) || 'a'); ERROR: XX000: tsquery stack too small SELECT to_tsquery('simple', repeat('!', 33) || 'a'); ERROR: XX000: tsquery stack too small Because this is elog() rather than ereturn(escontext, ...), it bypasses the soft-error machinery used since 16: SELECT pg_input_is_valid(repeat('!', 32) || 'a', 'tsquery'); -- t SELECT pg_input_is_valid(repeat('!', 33) || 'a', 'tsquery'); ERROR: XX000: tsquery stack too small and COPY ... (ON_ERROR ignore) aborts the whole load instead of skipping the row: CREATE TABLE onerr (q tsquery); -- onerr.txt: a & b -- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!a (33 "!") -- c & d \copy onerr from 'onerr.txt' (on_error ignore) ERROR: XX000: tsquery stack too small CONTEXT: COPY onerr, line 2, column q: "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!a" SELECT count(*) FROM onerr; -- 0 Expected: an ordinary user-facing error with a proper SQLSTATE (e.g. 54001 statement_too_complex or 54000 program_limit_exceeded), raised through the soft-error path so that pg_input_is_valid() returns false and ON_ERROR ignore skips the row. websearch_to_tsquery() is documented for raw user search input, so an XX000 from 33 hyphens typed into a search box is the wrong category. Actual: XX000 internal_error, not catchable by pg_input_is_valid() or ON_ERROR ignore. For comparison, intarray's copy of the same parser (contrib/intarray/ _int_bool.c:181-184) was converted when soft errors were introduced: if (lenstack =3D=3D STACKDEPTH) ereturn(state->escontext, ERR, (errcode(ERRCODE_STATEMENT_TOO_COMPLEX), errmsg("statement too complex"))); SELECT pg_input_is_valid(repeat('!', 17) || '1', 'query_int'); -- f The third copy, contrib/ltree/ltxtquery_io.c:252 (elog(ERROR, "stack too short")), behaves like tsquery: 33 stacked "!" give XX000 and pg_input_is_valid(..., 'ltxtquery') raises. That one was noted earlier in https://www.postgresql.org/message-id/749c63a4-ff67-76a8-e6d4-53b293931c81@= gmail.com Suggested fix: pass the TSQueryParserState to pushOpStack() and report the overflow with errsave(state->escontext, ...) as intarray does (e.g. ERRCODE_STATEMENT_TOO_COMPLEX, "tsquery is too complex", errdetail naming the limit), then return; makepol() already checks SOFT_ERROR_OCCURRED(state->escontext) after each token and returns, so no other plumbing is needed. The same change applies to ltxtquery_io.c's makepol(). Raising STACKDEPTH alone would not address the error class or the soft-error escape.