]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix expanding 'bounds' in pg_trgm's calc_word_similarity() function
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Fri, 20 Feb 2026 09:56:42 +0000 (11:56 +0200)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Fri, 20 Feb 2026 09:56:42 +0000 (11:56 +0200)
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

contrib/pg_trgm/trgm_op.c

index 5fba594b61f08be4ff98198760198ba75c8995be..ee89e548d16cd767f2ab2f5811597cc0b70ecddd 100644 (file)
@@ -533,7 +533,7 @@ generate_trgm_only(growable_trgm_array *dst, char *str, int slen, TrgmBound **bo
                {
                        if (bounds_allocated < dst->length)
                        {
-                               bounds = repalloc0_array(bounds, TrgmBound, bounds_allocated, dst->allocated);
+                               bounds = *bounds_p = repalloc0_array(bounds, TrgmBound, bounds_allocated, dst->allocated);
                                bounds_allocated = dst->allocated;
                        }