Re: BUG #19701: GIN trigram index loses rows at similarity_threshold 0 - Mailing list pgsql-bugs

From Manu
Subject Re: BUG #19701: GIN trigram index loses rows at similarity_threshold 0
Date
Msg-id 179096406728.463468.10787135519393288680@gmail.com
Whole thread
In response to Re: BUG #19701: GIN trigram index loses rows at similarity_threshold 0  (Palak Chaturvedi <chaturvedipalak1911@gmail.com>)
List pgsql-bugs
Hi Palak,

> No further comments from me. The patch look good to me.

Thanks for the review.

Before anyone picks it up: cfbot fails v2 on the two Linux tasks
(CF 7382).  Those builds use -fsanitize=undefined, and the server aborts
on the new "'' <<% t" query:

  runtime error: load of value 126, which is not a valid value for
  type 'bool' (calc_word_similarity, trgm_op.c:922)

The bug is not in v2; v2 only reaches it.  After its merge loop,
calc_word_similarity() reads found[j] once more.  When neither string
has a trigram, found[] has no elements and that read is past its end
(126 is 0x7E, the sentinel byte after a chunk in cassert builds).
Master does the same with "SELECT word_similarity('', '')".  The value
never changes the result: with no trigrams in the second string the
similarity is 0 without using it.

v3 attached:

0001 checks len > 0 before that read, with a test for
     word_similarity('', '').
0002 is v2, unchanged.

Built with the same sanitizer flags as cfbot, plus --enable-cassert:

  master, 0001's test without its fix: aborts
  master + v2: aborts on '' <<% t
  master + v3: all 4 pg_trgm tests pass
  REL_14_STABLE + v3: all 4 pg_trgm tests pass

Regards,
Manu

Attachment

pgsql-bugs by date:

Previous
From: Thiago Bonfante
Date:
Subject: Re: Backend crash (signal 11) in pg_trgm makesign() after ALTER TABLE ... SET STORAGE on a column with a gist_trgm_ops index
Next
From: Nate Clark
Date:
Subject: Re: BUG #19720: pg_trgm GiST index corruption from gtrgm_union() dropping SIGNKEY