mirror of
https://git.postgresql.org/git/postgresql.git
synced 2026-02-23 14:57:03 +08:00
With GB18030, prevent SIGSEGV from reading past end of allocation.
With GB18030 as source encoding, applications could crash the server via SQL functions convert() or convert_from(). Applications themselves could crash after passing unterminated GB18030 input to libpq functions PQescapeLiteral(), PQescapeIdentifier(), PQescapeStringConn(), or PQescapeString(). Extension code could crash by passing unterminated GB18030 input to jsonapi.h functions. All those functions have been intended to handle untrusted, unterminated input safely. A crash required allocating the input such that the last byte of the allocation was the last byte of a virtual memory page. Some malloc() implementations take measures against that, making the SIGSEGV hard to reach. Back-patch to v13 (all supported versions). Author: Noah Misch <noah@leadboat.com> Author: Andres Freund <andres@anarazel.de> Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com> Backpatch-through: 13 Security: CVE-2025-4207
This commit is contained in:
@ -300,11 +300,14 @@ insert into gb18030_inputs values
|
||||
('\x666f6f84309c38', 'valid, translates to UTF-8 by mapping function'),
|
||||
('\x666f6f84309c', 'incomplete char '),
|
||||
('\x666f6f84309c0a', 'incomplete char, followed by newline '),
|
||||
('\x666f6f84', 'incomplete char at end'),
|
||||
('\x666f6f84309c3800', 'invalid, NUL byte'),
|
||||
('\x666f6f84309c0038', 'invalid, NUL byte');
|
||||
|
||||
-- Test GB18030 verification
|
||||
select description, inbytes, (test_conv(inbytes, 'gb18030', 'gb18030')).* from gb18030_inputs;
|
||||
-- Test GB18030 verification. Round-trip through text so the backing of the
|
||||
-- bytea values is palloc, not shared_buffers. This lets Valgrind detect
|
||||
-- reads past the end.
|
||||
select description, inbytes, (test_conv(inbytes::text::bytea, 'gb18030', 'gb18030')).* from gb18030_inputs;
|
||||
-- Test conversions from GB18030
|
||||
select description, inbytes, (test_conv(inbytes, 'gb18030', 'utf8')).* from gb18030_inputs;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user