pgsql: Fix calculating length of match to localized month/weekday names - Mailing list pgsql-committers

From Álvaro Herrera
Subject pgsql: Fix calculating length of match to localized month/weekday names
Date
Msg-id E1wrc8y-00000000JFw-3DGN@gemulon.postgresql.org
Whole thread
List pgsql-committers
Fix calculating length of match to localized month/weekday names

seq_search_localized() returns the length of the matching prefix in
*len, but because it internally case-folds the inputs, it gets
confused on the length. The caller expects to get the length of the
prefix in the original string, but what it actually returns is the
length of the prefix after case-folding, which can be different if the
case-folded characters have different byte-length than the original,
or with ICU, if the case-folding changes the number of characters
(e.g. "ß", the German double s).

To fix, once we have determined that we have a match, work harder to
find the match's length in the original string.  This adds some
overhead, but the strings are expected to be short.

The function does "case-folding" by converting a string to upper-case,
then to lower-case, which is a little ugly given that we have
dedicated functions for case-folding nowadays. But switching to that
doesn't seem appropriate to backpatch in a security fix, and that's
not available in older stable versions, anyway.

Author: Heikki Linnakangas <heikki.linnakangas@iki.fi>
Reported-by: Xint Code
Reviewed-by: Jeff Davis <pgsql@j-davis.com>

Branch
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/011384ba45fe193131f92c2d16c45f20d909301d

Modified Files
--------------
src/backend/utils/adt/formatting.c               | 163 +++++++++++++++++++----
src/test/regress/expected/collate.linux.utf8.out |  18 +++
src/test/regress/sql/collate.linux.utf8.sql      |   3 +
3 files changed, 158 insertions(+), 26 deletions(-)


pgsql-committers by date:

Previous
From: Michael Paquier
Date:
Subject: pgsql: Initialize read stream before fetching metapage in hash bulk-del
Next
From: Melanie Plageman
Date:
Subject: pgsql: Make local buffers pin limit more conservative