Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xR5j2-00000000fn7-1gKQ for pgsql-bugs@arkaria.postgresql.org; Wed, 11 Nov 2026 10:38:44 +0000 Received: from localhost ([127.0.0.1]:44518 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xR5iz-0000000AE0t-1V39 for pgsql-bugs@arkaria.postgresql.org; Wed, 11 Nov 2026 10:38:41 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]:41562) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xR147-00000008qFF-0j5p for pgsql-bugs@lists.postgresql.org; Wed, 11 Nov 2026 05:40:11 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xR144-00000000PGP-0Mto for pgsql-bugs@lists.postgresql.org; Wed, 11 Nov 2026 05:40:11 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=CvCRf/o+hIWI9NNyAK+1JbjRI5mIP0nTNU65nc1lBlU=; b=vuYOkBvx82oZsaafjRHx/NCMKd S8WkdfDCME86Ks2i3P0bir6AjlP/v27ybIDVUhSmKv37Sd24LQ9wDcGsfMmKCgvBof1bU2Ok/OZRb 3ugJfQv/TrUQ9PbjwLCVgZ9RRud3HCY7x5pnkSHwj3TYyU4Bl1xy7OeHlF9GJJ5KDZyyRM2q9rR+4 etKWTmCgvnThkkbRPFgWo9RM+HmBxBaChs5KjFFzL3vjg9ax9EG2SQYL6PGW3C1/pxelKq8L1xK4E WKxbl7P7iyJgtW69V+xA+uxCoUK0RqNAMLjljcylJcFWGGYr9/6Tc7c6bliGIVvUcgu1YLum0IbWk YlDls7Nw==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xR140-00000000szi-1wbb for pgsql-bugs@lists.postgresql.org; Wed, 11 Nov 2026 05:40:06 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xR13z-00000002Il5-322V for pgsql-bugs@lists.postgresql.org; Wed, 11 Nov 2026 05:40:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19866: acldefault() emits invalid UTF-8 for a high-bit "char" value To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: 1548140642@qq.com Reply-To: 1548140642@qq.com, pgsql-bugs@lists.postgresql.org Date: Wed, 11 Nov 2026 05:39:16 +0000 Message-ID: <19866-6c04f56db1b73ac6@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19866 Logged by: Milo Email address: 1548140642@qq.com PostgreSQL version: 18.6 Operating system: Linux/amd64 Description: =20 In a UTF-8 database, pg_catalog.acldefault(char, oid) produces MESSAGE_TEXT containing a raw, invalid UTF-8 byte when the invalid object type is the one-byte value 0x80. A client that decodes server responses as UTF-8 can therefore fail to decode the diagnostic. The diagnostic should remain valid in the server encoding. The byte should be rendered in an encoding-safe form such as \200, as charout() and the setweight() diagnostic do, rather than inserted as a raw standalone byte. How to repeat: Save the following as reproducer.sql and run `psql -X -d postgres -f reproducer.sql` against a UTF-8 database. CREATE TEMP TABLE encoding_result (tested_function text, message_is_invalid_utf8 boolean, validation_sqlstate text); DO $test$ DECLARE captured_message text; invalid_utf8 boolean; validation_state text; BEGIN BEGIN PERFORM pg_catalog.acldefault('\200'::pg_catalog."char", 10::oid); RAISE EXCEPTION 'expected acldefault() to reject the invalid object type'; EXCEPTION WHEN OTHERS THEN GET STACKED DIAGNOSTICS captured_message =3D MESSAGE_TEXT; END; invalid_utf8 :=3D false; validation_state :=3D NULL; BEGIN -- Converting away from the database encoding forces validation of the -- UTF-8 source bytes; UTF8-to-UTF8 conversion would be optimized away. PERFORM pg_catalog.convert_to(captured_message, 'LATIN1'); EXCEPTION WHEN OTHERS THEN invalid_utf8 :=3D true; GET STACKED DIAGNOSTICS validation_state =3D RETURNED_SQLSTATE; END; INSERT INTO encoding_result VALUES ('acldefault', invalid_utf8, validation_state); BEGIN PERFORM pg_catalog.setweight('a'::pg_catalog.tsvector, '\200'::pg_catalog."char"); RAISE EXCEPTION 'expected setweight() to reject the invalid weight'; EXCEPTION WHEN OTHERS THEN GET STACKED DIAGNOSTICS captured_message =3D MESSAGE_TEXT; END; invalid_utf8 :=3D false; validation_state :=3D NULL; BEGIN PERFORM pg_catalog.convert_to(captured_message, 'LATIN1'); EXCEPTION WHEN OTHERS THEN invalid_utf8 :=3D true; GET STACKED DIAGNOSTICS validation_state =3D RETURNED_SQLSTATE; END; INSERT INTO encoding_result VALUES ('setweight_control', invalid_utf8, validation_state); END $test$; SELECT tested_function, message_is_invalid_utf8, validation_sqlstate FROM encoding_result ORDER BY tested_function; DROP TABLE encoding_result; The recorded output was: CREATE TABLE DO tested_function | message_is_invalid_utf8 | validation_sqlstate -------------------+-------------------------+--------------------- acldefault | t | 22021 setweight_control | f | (2 rows) DROP TABLE The acldefault() message therefore fails UTF-8 source validation with SQLSTATE 22021, while the diagnostic produced by setweight() for the same one-byte value remains valid. The issue was reproduced on PostgreSQL 18.6 and PostgreSQL 20devel on Linux/amd64. This occurs when acldefault() is called with the high-bit one-byte "char" value 0x80 as an invalid object type.