summaryrefslogtreecommitdiff
path: root/contrib/pg_trgm/sql
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2023-03-11 12:15:41 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2023-03-11 12:15:41 -0500
commit1925ac281a238fab50e208548f98daffdaaa0896 (patch)
treedcba116a9bd634b7b1c60b7c02c5b3c67124f7f1 /contrib/pg_trgm/sql
parentd66bb048c3130c7b7a4876fc9050291f9e4cad2b (diff)
downloadpostgresql-1925ac281a238fab50e208548f98daffdaaa0896.tar.gz
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
Diffstat (limited to 'contrib/pg_trgm/sql')
-rw-r--r--contrib/pg_trgm/sql/pg_word_trgm.sql3
1 files changed, 3 insertions, 0 deletions
diff --git a/contrib/pg_trgm/sql/pg_word_trgm.sql b/contrib/pg_trgm/sql/pg_word_trgm.sql
index d9fa1c55e5..d2ada49133 100644
--- a/contrib/pg_trgm/sql/pg_word_trgm.sql
+++ b/contrib/pg_trgm/sql/pg_word_trgm.sql
@@ -43,3 +43,6 @@ select t,word_similarity('Baykal',t) as sml from test_trgm2 where 'Baykal' <% t
select t,word_similarity('Kabankala',t) as sml from test_trgm2 where 'Kabankala' <% t order by sml desc, t;
select t,word_similarity('Baykal',t) as sml from test_trgm2 where t %> 'Baykal' order by sml desc, t;
select t,word_similarity('Kabankala',t) as sml from test_trgm2 where t %> 'Kabankala' order by sml desc, t;
+
+-- test unsatisfiable pattern
+select * from test_trgm2 where t ~ '.*$x';