Re: Small patch to improve safety of utf8_to_unicode(). - Mailing list pgsql-hackers

From Jeff Davis
Subject Re: Small patch to improve safety of utf8_to_unicode().
Date
Msg-id 765830662fd26e0861189c775443fc76ea8213da.camel@j-davis.com
Whole thread
In response to Re: Small patch to improve safety of utf8_to_unicode().  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Small patch to improve safety of utf8_to_unicode().
List pgsql-hackers
On Mon, 2026-07-13 at 13:20 -0400, Tom Lane wrote:
> I wrote:
> > Well, there aren't going to be any ASCII characters that produce 12
> > bytes, and probably not any LATIN1 characters either, so I think we
> > could assume that the shortest input character that could produce
> > such a long output would be 3 bytes.
>
> Ah sorry, I should have written BMP not LATIN1.  Maybe it still holds
> across that set, but I'm less sure.

Attached a patch. I added some perl code to check that the expansion
factor of the UTF8 representation doesn't exceed 3, and added a static
assert in the C code to compare to MaxAllocSize.

Regards,
    Jeff Davis


Attachment

pgsql-hackers by date:

Previous
From: Amit Kapila
Date:
Subject: Re: sequencesync worker race with REFRESH SEQUENCES
Next
From: shveta malik
Date:
Subject: Re: sequencesync worker race with REFRESH SEQUENCES