pgsql: hashtext: fix fragile code. - Mailing list pgsql-committers

From Jeff Davis
Subject pgsql: hashtext: fix fragile code.
Date
Msg-id E1wx9yb-00000001PT8-1Osu@gemulon.postgresql.org
Whole thread
List pgsql-committers
hashtext: fix fragile code.

Previously, in the path for non-deterministic collations, the code
assumed that bsize==rsize. That assumption seems to be true for ICU,
and all non-deterministic collations are ICU, so it's not known to be
an actual bug.

The only known place where bsize may not equal rsize is in the libc
provider, where strxfrm() can return an upper bound of the size needed
to store the result. That means the initial call to determine the
buffer size (with dest==NULL, n==0) could return a larger number than
the actual call with an adequate dest buffer. That's OK, because libc
locales are always deterministic.

Commit 679c5084cf2 partially fixed the assumption, but missed this
part. Fix it, and add a more prominent documentation note.

Reviewed-by: Haibo Yan <tristan.yim@gmail.com>
Discussion: https://postgr.es/m/CABXr29Hb31nkj1g2Jmk+1BhAm=3ecGs_pWy4tU++j8CQBnbMxQ@mail.gmail.com
Backpatch-through: 16

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/f61d6b0e1329841ef8bb0a337ac95700885fe772

Modified Files
--------------
src/backend/access/hash/hashfunc.c |  4 ++--
src/backend/utils/adt/pg_locale.c  | 24 +++++++++++++++++++++---
src/backend/utils/adt/varchar.c    |  4 ++--
3 files changed, 25 insertions(+), 7 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Micro-optimize appendStringInfo[VA].
Next
From: Bruce Momjian
Date:
Subject: pgsql: doc: fix wording in SELECT docs