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 1xRYdu-000000014up-0UDR for pgsql-bugs@arkaria.postgresql.org; Thu, 12 Nov 2026 17:31:22 +0000 Received: from localhost ([127.0.0.1]:47716 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xRYds-0000000450q-0nW7 for pgsql-bugs@arkaria.postgresql.org; Thu, 12 Nov 2026 17:31:20 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]:57168) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xR9Sf-0000000BbrW-2yri for pgsql-bugs@lists.postgresql.org; Wed, 11 Nov 2026 14:38: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 1xR9Se-00000000O3v-3bbp for pgsql-bugs@lists.postgresql.org; Wed, 11 Nov 2026 14:38: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=2iIKAAA92Lc2xCZcEr2D5ERNzVRfiaZKUcTDSVUyPmY=; b=PsNp792Y9H/ZiD5kkSNSMUSj2+ MkW0DL9QLsNYHukkLP5eUT4tQs8BrXdtjIYWVBsUSec+lZuPiohZRj7lybYb7HOCf0gSQ5yGzsWl0 0Jz7r84s/31Ou+loxyILUyeG88wziaaKORxvJbPKO+y+sfK65lYHUvBvGd3/3cBivh8GWoniA7wpJ lQYS/bYGctYJZo7Dwk22Go8+eYuGrMt07Rhj8LGy4oATmYKKv+jZYLVTUS5IWh04VxhjHhqdci4A4 F1IkNM89988Nn3tDN0aEJnqpONzQCl6x66YIYi/sXk6CRdzDXrOpsCcttjCDwchVsX3B8lRQYDzc3 DNN3owhw==; 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 1xR9Sd-0000000147n-48WH for pgsql-bugs@lists.postgresql.org; Wed, 11 Nov 2026 14:38: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 1xR9Sd-00000002l17-0lIU for pgsql-bugs@lists.postgresql.org; Wed, 11 Nov 2026 14:38:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19885: pg_input_is_valid(tsquery) throws stack depth error instead of returning false To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: imchifan8@gmail.com Reply-To: imchifan8@gmail.com, pgsql-bugs@lists.postgresql.org Date: Wed, 11 Nov 2026 14:37:34 +0000 Message-ID: <19885-741df1acb48cdad1@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: 19885 Logged by: Noah Email address: imchifan8@gmail.com PostgreSQL version: 18.6 Operating system: Linux/amd64 Description: =20 pg_input_is_valid() throws SQLSTATE 54001 while validating a deeply parenthesized tsquery when max_stack_depth is 100kB. Ordinary malformed tsquery input returns false through the soft-error interface, but the recursive nesting path raises =E2=80=9Cstack depth limit exceeded.=E2=80=9D= Both inputs are invalid, so pg_input_is_valid() should return false for both rather than letting the input function's error escape. How to repeat: Save the following as case.sql and run it with `psql -X -f case.sql`: ``` \set ON_ERROR_STOP on SET max_stack_depth =3D '100kB'; DO $case$ DECLARE result boolean; BEGIN -- Control: ordinary bad input is reported through the soft-error API. BEGIN result :=3D pg_input_is_valid( 'word &', 'tsquery'); RAISE NOTICE 'control=3Dreturned value=3D%', result; EXCEPTION WHEN OTHERS THEN RAISE NOTICE 'control=3Dthrew sqlstate=3D% message=3D%', SQLSTATE, SQLERRM; END; -- Candidate: equivalent user-controlled complexity through recursion. BEGIN result :=3D pg_input_is_valid( repeat('(', 1000) || 'word' || repeat(')', 1000), 'tsquery'); RAISE NOTICE 'nested=3Dreturned value=3D%', result; EXCEPTION WHEN OTHERS THEN RAISE NOTICE 'nested=3Dthrew sqlstate=3D% message=3D%', SQLSTATE, SQLERRM; END; END $case$; RESET max_stack_depth; ``` The recorded result was: ``` SET NOTICE: control=3Dreturned value=3Df NOTICE: nested=3Dthrew sqlstate=3D54001 message=3Dstack depth limit exceed= ed DO RESET ``` The issue was reproduced on PostgreSQL 18.6 on Linux/amd64. The server remained available after the statement, and no server-log error accompanied the caught exception. This occurs when pg_input_is_valid checks a deeply parenthesized tsquery under a low max_stack_depth setting.