postgresql/src/backend
Tom Lane f20b840813 Prevent buffer overrun in unicode_normalize().
Some UTF8 characters decompose to more than a dozen codepoints.
It is possible for an input string that fits into well under
1GB to produce more than 4G decomposed codepoints, causing
unicode_normalize()'s decomp_size variable to wrap around to a
small positive value.  This results in a small output buffer
allocation and subsequent buffer overrun.

To fix, test after each addition to see if we've overrun MaxAllocSize,
and break out of the loop early if so.  In frontend code we want to
just return NULL for this failure (treating it like OOM).  In the
backend, we can rely on the following palloc() call to throw error.

I also tightened things up in the calling functions in varlena.c,
using size_t rather than int and allocating the input workspace
with palloc_array().  These changes are probably unnecessary
given the knowledge that the original input and the normalized
output_chars array must fit into 1GB, but it's a lot easier to
believe the code is safe with these changes.

Reported-by: Xint Code
Reported-by: Bruce Dang <bruce@calif.io>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Co-authored-by: Heikki Linnakangas <hlinnaka@iki.fi>
Backpatch-through: 14
Security: CVE-2026-6473
2026-05-11 05:13:49 -07:00
..
access Fix multixact backwards-compatibility with CHECKPOINT race condition 2026-03-23 12:02:27 +02:00
archive Redesign archive modules 2023-02-17 14:26:42 +09:00
backup Fix error message related to end TLI in backup manifest 2026-01-18 17:25:01 +09:00
bootstrap Fix CREATE INDEX progress reporting for multi-level partitioning. 2023-03-25 15:34:03 -04:00
catalog Don't call CheckAttributeType() with InvalidOid on dropped cols 2026-04-23 21:33:02 +03:00
commands Allow ALTER INDEX .. ATTACH PARTITION to validate a parent index 2026-04-22 10:34:37 +09:00
executor Fix incorrect logic for hashed IN / NOT IN with non-strict operators 2026-04-24 14:04:31 +12:00
foreign Restrict accesses to non-system views and foreign tables during pg_dump. 2024-08-05 06:05:28 -07:00
jit jit: No backport::SectionMemoryManager for LLVM 22. 2026-04-03 15:01:56 +13:00
lib Accommodate very large dshash tables. 2024-12-17 15:24:45 -06:00
libpq Fix build breakage on Solaris-alikes with late-model GCC. 2025-07-23 15:44:29 -04:00
main Avoid possible crash within libsanitizer. 2025-11-05 11:09:30 -05:00
nodes Build whole-row Vars the same way during parsing and planning. 2025-03-12 11:47:19 -04:00
optimizer Consider collation when proving subquery uniqueness 2026-05-05 10:31:17 +09:00
parser Fix attnum remapping in generateClonedExtStatsStmt() 2026-04-30 11:14:26 -04:00
partitioning Fix creation of partition descriptor during concurrent detach+drop 2024-08-12 18:17:56 -04:00
po Translation updates 2026-05-11 13:07:36 +02:00
port Don't treat EINVAL from semget() as a hard failure. 2025-08-13 11:59:47 -04:00
postmaster Fix orphaned processes when startup process fails during PM_STARTUP 2026-04-21 09:40:06 +09:00
regex Harden our regex engine against integer overflow in size calculations. 2026-05-11 05:13:49 -07:00
replication Flush statistics during idle periods in parallel apply worker. 2026-04-20 10:13:55 +05:30
rewrite Fix incorrect NEW references to generated columns in rule rewriting 2026-04-21 14:33:07 +09:00
snowball Avoid null pointer dereference crash after OOM in Snowball stemmers. 2025-02-18 21:23:59 -05:00
statistics Fix set of issues with extended statistics on expressions 2026-03-02 09:38:44 +09:00
storage Make palloc_array() and friends safe against integer overflow. 2026-05-11 05:13:49 -07:00
tcop Check for CREATE privilege on the schema in CREATE STATISTICS. 2025-11-10 09:00:00 -06:00
tsearch Fix overflows with ts_headline() 2026-05-11 05:13:49 -07:00
utils Prevent buffer overrun in unicode_normalize(). 2026-05-11 05:13:49 -07:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
common.mk Blind attempt to fix LLVM dependency in the backend 2022-09-15 10:53:48 +07:00
Makefile Fix make headerscheck 2024-04-27 11:38:41 +07:00
meson.build Add win32ver data to meson-built postgres.exe. 2023-06-12 07:40:38 -07:00
nls.mk Add missing gettext triggers 2023-05-10 13:51:51 +02:00