]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Prevent buffer overrun in unicode_normalize().
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 11 May 2026 12:13:49 +0000 (05:13 -0700)
committerNoah Misch <noah@leadboat.com>
Mon, 11 May 2026 12:13:49 +0000 (05:13 -0700)
commitf20b840813f579062cc5de0a9a266dc8d5590fc7
treeacce60b6e427100c6014be170dc7c7e790eeb8bc
parenta4f089c79b3f7c1790d400ec72a9258d55165dbf
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
src/backend/utils/adt/varlena.c
src/common/unicode_norm.c