Fix expanding 'bounds' in pg_trgm's calc_word_similarity() function

Heikki Linnakangas <heikki.linnakangas@iki.fi>

Commit: 041e02e6a6110af871b909c55f1a1bd9d5a66cdb
Author: Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date: 2026-02-20T09:56:50Z
Releases: 18.3
Fix expanding 'bounds' in pg_trgm's calc_word_similarity() function

If the 'bounds' array needs to be expanded, because the input contains
more trigrams than the initial guess, the code didn't return the
reallocated array correctly to the caller. That could lead to a crash
in the rare case that the input string becomes longer when it's
lower-cased. The only known instance of that is when an ICU locale is
used with certain single-byte encodings. This was an oversight in
commit 00896ddaf41f.

Author: Zsolt Parragi <zsolt.parragi@percona.com>
Backpatch-through: 18

Files

PathChange+/−
contrib/pg_trgm/trgm_op.c modified +1 −1