pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix misbehavior in contrib/pg_trgm with an unsatisfiable regex.
Date: Sat, 11 Mar 2023 17:15:55 +0000
Message-ID: <E1pb2p0-00330w-Nb@gemulon.postgresql.org> (raw)

Fix misbehavior in contrib/pg_trgm with an unsatisfiable regex.

If the regex compiler can see that a regex is unsatisfiable
(for example, '$foo') then it may emit an NFA having no arcs.
pg_trgm's packGraph function did the wrong thing in this case;
it would access off the end of a work array, and with bad luck
could produce a corrupted output data structure causing more
problems later.  This could end with wrong answers or crashes
in queries using a pg_trgm GIN or GiST index with such a regex.

Fix by not trying to de-duplicate if there aren't at least 2 arcs.

Per bug #17830 from Alexander Lakhin.  Back-patch to all supported
branches.

Discussion: https://postgr.es/m/17830-57ff5f89bdb02b09@postgresql.org

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/786528039911c2270589bb690afab20116ee88f3

Modified Files
--------------
contrib/pg_trgm/expected/pg_word_trgm.out |  6 ++++++
contrib/pg_trgm/sql/pg_word_trgm.sql      |  3 +++
contrib/pg_trgm/trgm_regexp.c             | 26 ++++++++++++++++----------
3 files changed, 25 insertions(+), 10 deletions(-)



view thread (6+ messages)  latest in thread

Message-ID: <E1pb2p0-00330w-Nb@gemulon.postgresql.org>
Permalink:  ../E1pb2p0-00330w-Nb@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1pb2p0-00330w-Nb@gemulon.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-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Fix misbehavior in contrib/pg_trgm with an unsatisfiable regex.
  In-Reply-To: <E1pb2p0-00330w-Nb@gemulon.postgresql.org>
  References: <E1pb2p0-00330w-Nb@gemulon.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