From: Jeff Davis <pgsql@j-davis.com>
To: pgsql-hackers@postgresql.org
Subject: Fix for fragile code in ltree/crc32.c
Date: Tue, 18 Aug 2026 17:05:29 -0700
Message-ID: <2cfbc37ae8deccd3825e36b7f31c391cbf8ff9b8.camel@j-davis.com> (raw)
The buffer in ltree_crc32_sz() is more than large enough in practice,
but it didn't explicitly leave room for the NUL byte. Patch attached.
Regards,
Jeff Davis
Attachments:v1-0001-ltree-crc32.c-fix-fragile-code.patch (text/x-patch, 1.3K) download
From f0d8e75f7385af2b7e9c621a2538da5e4e9e0148 Mon Sep 17 00:00:00 2001
From: Jeff Davis <jeff@j-davis.com>
Date: Tue, 18 Aug 2026 14:57:32 -0700
Subject: [PATCH v1] ltree/crc32.c: fix fragile code.
Explicitly make space for the NUL when casefolding.
No known bug in the previous code, because the buffer was more than
large enough for folding any codepoint with enough room left for a
NUL. But it was fragile, and would break if UNICODE_CASEMAP_BUFSZ were
a tighter bound.
Backpatch-through: 18
---
contrib/ltree/crc32.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/contrib/ltree/crc32.c b/contrib/ltree/crc32.cindex d21bed31fdd..617cc652a7a 100644--- a/contrib/ltree/crc32.c+++ b/contrib/ltree/crc32.c@@ -32,13 +32,13 @@ ltree_crc32_sz(const char *buf, int size)
INIT_TRADITIONAL_CRC32(crc);
while (size > 0)
{
- char foldstr[UNICODE_CASEMAP_BUFSZ];+ char foldstr[UNICODE_CASEMAP_BUFSZ + 1];
int srclen = pg_mblen_range(p, end);
size_t foldlen;
/* fold one codepoint at a time */
- foldlen = pg_strfold(foldstr, UNICODE_CASEMAP_BUFSZ, p, srclen,- locale);+ foldlen = pg_strfold(foldstr, sizeof(foldstr), p, srclen, locale);+ Assert(foldlen < sizeof(foldstr));
COMP_TRADITIONAL_CRC32(crc, foldstr, foldlen);
--
2.43.0
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: pgsql@j-davis.com
Subject: Re: Fix for fragile code in ltree/crc32.c
In-Reply-To: <2cfbc37ae8deccd3825e36b7f31c391cbf8ff9b8.camel@j-davis.com>
References: <2cfbc37ae8deccd3825e36b7f31c391cbf8ff9b8.camel@j-davis.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox