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 <[email protected]> Reported-by: Xint Code Reviewed-by: Jeff Davis <[email protected]> Branch ------ REL_15_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/0de744cd5281021c96ce7366efae2b17321909f8 Modified Files -------------- src/backend/utils/adt/formatting.c | 137 +++++++++++++++++++---- src/test/regress/expected/collate.linux.utf8.out | 18 +++ src/test/regress/sql/collate.linux.utf8.sql | 3 + 3 files changed, 138 insertions(+), 20 deletions(-)
