]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix encoding length for EUC_CN.
authorThomas Munro <tmunro@postgresql.org>
Wed, 4 Feb 2026 12:04:24 +0000 (01:04 +1300)
committerThomas Munro <tmunro@postgresql.org>
Sun, 8 Feb 2026 23:08:58 +0000 (12:08 +1300)
commitaf79c30dc3e5369cd6d2bfdccd2c2c0ffbd60ef3
tree45309b522bc01e78570ba24e7105f5fb47e5f3bb
parent00896ddaf41fa7b725991120678d544c18c6af70
Fix encoding length for EUC_CN.

While EUC_CN supports only 1- and 2-byte sequences (CS0, CS1), the
mb<->wchar conversion functions allow 3-byte sequences beginning SS2,
SS3.

Change pg_encoding_max_length() to return 3, not 2, to close a
hypothesized buffer overrun if a corrupted string is converted to wchar
and back again in a newly allocated buffer.  We might reconsider that in
master (ie harmonizing in a different direction), but this change seems
better for the back-branches.

Also change pg_euccn_mblen() to report SS2 and SS3 characters as having
length 3 (following the example of EUC_KR).  Even though such characters
would not pass verification, it's remotely possible that invalid bytes
could be used to compute a buffer size for use in wchar conversion.

Security: CVE-2026-2006
Backpatch-through: 14
Author: Thomas Munro <thomas.munro@gmail.com>
Reviewed-by: Noah Misch <noah@leadboat.com>
Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
src/common/wchar.c