Re: BUG #19406: substring(text) fails on valid UTF-8 toasted value in PostgreSQL 15.16
Noah Misch <noah@leadboat.com>
From: Noah Misch <noah@leadboat.com>
To: ranvis@gmail.com, pgsql-bugs@lists.postgresql.org
Cc: thomas.munro@gmail.com
Date: 2026-02-14T05:38:21Z
Lists: pgsql-bugs
Attachments
- toast-slice-mblen-v3.patch (text/plain) patch v3
- mblen-valgrind-after-report-v1.patch (text/plain) patch v1
On Fri, Feb 13, 2026 at 04:21:13PM -0800, Noah Misch wrote:
> Review welcome. I have a Valgrind test run ongoing.
Valgrind found the complaint below, but I think this an instrumentation
problem. I've added a fix for that instrumentation. I also made minor edits
to the log message of the main patch, hence v3.
The release team is preparing to announce a 2026-02-26 out-of-cycle release in
light of this regression. I plan to push these fixes at 2026-02-14T20:00+0000
to unblock that formal announcement.
==00:00:01:11.756 3464664== VALGRINDERROR-BEGIN
==00:00:01:11.756 3464664== Unaddressable byte(s) found during client check request
==00:00:01:11.769 3464664== at 0xC6076A: pg_mblen_with_len (mbutils.c:1115)
==00:00:01:11.769 3464664== by 0xC07CD3: pg_mbcharcliplen_chars (varlena.c:807)
==00:00:01:11.770 3464664== by 0xC07AAD: text_substring (varlena.c:732)
==00:00:01:11.770 3464664== by 0xC07797: text_substr (varlena.c:553)
==00:00:01:11.770 3464664== by 0x779688: ExecInterpExpr (execExprInterp.c:953)
==00:00:01:11.770 3464664== by 0x77BBD6: ExecInterpExprStillValid (execExprInterp.c:2299)
==00:00:01:11.770 3464664== by 0x7DBBC4: ExecEvalExprNoReturn (executor.h:423)
==00:00:01:11.770 3464664== by 0x7DBC73: ExecEvalExprNoReturnSwitchContext (executor.h:464)
==00:00:01:11.770 3464664== by 0x7DBCD3: ExecProject (executor.h:496)
==00:00:01:11.770 3464664== by 0x7DC134: ExecScanExtended (execScan.h:234)
==00:00:01:11.770 3464664== by 0x7DC474: ExecSeqScanWithProject (nodeSeqscan.c:162)
==00:00:01:11.770 3464664== by 0x794561: ExecProcNodeFirst (execProcnode.c:469)
==00:00:01:11.770 3464664== Address 0x19340a5e is 12,062 bytes inside a block of size 12,064 alloc'd
==00:00:01:11.770 3464664== at 0x4C29F73: malloc (vg_replace_malloc.c:309)
==00:00:01:11.770 3464664== by 0xC79F03: AllocSetAllocLarge (aset.c:756)
==00:00:01:11.770 3464664== by 0xC7AA4C: AllocSetAlloc (aset.c:1033)
==00:00:01:11.770 3464664== by 0xC8B37E: palloc (mcxt.c:1408)
==00:00:01:11.770 3464664== by 0x4B0182: detoast_attr_slice (detoast.c:324)
==00:00:01:11.770 3464664== by 0xC5177F: pg_detoast_datum_slice (fmgr.c:1825)
==00:00:01:11.770 3464664== by 0xC07A11: text_substring (varlena.c:716)
==00:00:01:11.770 3464664== by 0xC07797: text_substr (varlena.c:553)
==00:00:01:11.770 3464664== by 0x779688: ExecInterpExpr (execExprInterp.c:953)
==00:00:01:11.770 3464664== by 0x77BBD6: ExecInterpExprStillValid (execExprInterp.c:2299)
==00:00:01:11.770 3464664== by 0x7DBBC4: ExecEvalExprNoReturn (executor.h:423)
==00:00:01:11.770 3464664== by 0x7DBC73: ExecEvalExprNoReturnSwitchContext (executor.h:464)
==00:00:01:11.770 3464664==
==00:00:01:11.770 3464664== VALGRINDERROR-END
{
<insert_a_suppression_name_here>
Memcheck:User
fun:pg_mblen_with_len
fun:pg_mbcharcliplen_chars
fun:text_substring
fun:text_substr
fun:ExecInterpExpr
fun:ExecInterpExprStillValid
fun:ExecEvalExprNoReturn
fun:ExecEvalExprNoReturnSwitchContext
fun:ExecProject
fun:ExecScanExtended
fun:ExecSeqScanWithProject
fun:ExecProcNodeFirst
}
2026-02-13 21:03:38.905 PST client backend[3464664] pg_regress/encoding ERROR: invalid byte sequence for encoding "UTF8": 0xe2 0x80
2026-02-13 21:03:38.905 PST client backend[3464664] pg_regress/encoding STATEMENT: SELECT SUBSTRING(c FROM 4001 FOR 1) FROM toast_3b_utf8;
**00:00:01:11.771 3464664** Valgrind detected 1 error(s) during execution of "SELECT SUBSTRING(c FROM 4001 FOR 1) FROM toast_3b_utf8;"
Commits
-
Suppress new "may be used uninitialized" warning.
- a0769e74d65d 14.22 landed
- ec86152e0209 15.17 landed
- 50d361f6223f 17.9 landed
- 2280ab354516 16.13 landed
- d04b34d685a2 18.3 landed
- 8cef93d8a588 19 (unreleased) landed
-
Fix SUBSTRING() for toasted multibyte characters.
- a20eb248c51a 15.17 landed
- 14b1fd6176cb 14.22 landed
- bdfb372280bc 16.13 landed
- 5d5232bc38d3 17.9 landed
- 6e045e1a6e3f 18.3 landed
- 9f4fd119b2cb 19 (unreleased) landed
-
pg_mblen_range, pg_mblen_with_len: Valgrind after encoding ereport.
- 44fc85bbf990 14.22 landed
- 8e73530f1546 17.9 landed
- 5b305ebcc9b5 15.17 landed
- 45eb47230d93 16.13 landed
- 4174e41b9e9e 18.3 landed
- 4644f8b23bb8 19 (unreleased) landed