pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: imchifan8@gmail.com
Subject: BUG #19885: pg_input_is_valid(tsquery) throws stack depth error instead of returning false
Date: Wed, 11 Nov 2026 14:37:34 +0000
Message-ID: <19885-741df1acb48cdad1@postgresql.org> (raw)

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:        

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 “stack depth limit exceeded.” 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 = '100kB';

DO $case$
DECLARE
    result boolean;
BEGIN
    -- Control: ordinary bad input is reported through the soft-error API.
    BEGIN
        result := pg_input_is_valid(
            'word &',
            'tsquery');
        RAISE NOTICE 'control=returned value=%', result;
    EXCEPTION WHEN OTHERS THEN
        RAISE NOTICE 'control=threw sqlstate=% message=%',
                     SQLSTATE, SQLERRM;
    END;

    -- Candidate: equivalent user-controlled complexity through recursion.
    BEGIN
        result := pg_input_is_valid(
            repeat('(', 1000) || 'word' || repeat(')', 1000),
            'tsquery');
        RAISE NOTICE 'nested=returned value=%', result;
    EXCEPTION WHEN OTHERS THEN
        RAISE NOTICE 'nested=threw sqlstate=% message=%',
                     SQLSTATE, SQLERRM;
    END;
END
$case$;

RESET max_stack_depth;
```

The recorded result was:

```
SET
NOTICE:  control=returned value=f
NOTICE:  nested=threw sqlstate=54001 message=stack depth limit exceeded
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.







view thread (2+ messages)  latest in thread

Message-ID: <19885-741df1acb48cdad1@postgresql.org>
Permalink:  ../19885-741df1acb48cdad1@postgresql.org/
Also on:    postgresql.org/message-id/19885-741df1acb48cdad1@postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, imchifan8@gmail.com
  Subject: Re: BUG #19885: pg_input_is_valid(tsquery) throws stack depth error instead of returning false
  In-Reply-To: <19885-741df1acb48cdad1@postgresql.org>
  References: <19885-741df1acb48cdad1@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox