pgsql: Add pg_encoding_set_invalid()

From: Andres Freund <andres(at)anarazel(dot)de>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Add pg_encoding_set_invalid()
Date: 2025-02-10 15:09:49
Message-ID: [email protected]
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Add pg_encoding_set_invalid()

There are cases where we cannot / do not want to error out for invalidly
encoded input. In such cases it can be useful to replace e.g. an incomplete
multi-byte characters with bytes that will trigger an error when getting
validated as part of a larger string.

Unfortunately, until now, for some encoding no such sequence existed. For
those encodings this commit removes one previously accepted input combination
- we consider that to be ok, as the chosen bytes are outside of the valid
ranges for the encodings, we just previously failed to detect that.

As we cannot add a new field to pg_wchar_table without breaking ABI, this is
implemented "in-line" in the newly added function.

Author: Noah Misch <noah(at)leadboat(dot)com>
Reviewed-by: Andres Freund <andres(at)anarazel(dot)de>
Backpatch-through: 13
Security: CVE-2025-1094

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/5bc33cbeae0e5cb8ecb410f8e47efb92811380fd

Modified Files
--------------
src/common/wchar.c | 55 +++++++++++++++++++++++-
src/include/mb/pg_wchar.h | 3 +-
src/test/regress/expected/conversion.out | 4 ++
src/test/regress/input/create_function_0.source | 5 +++
src/test/regress/output/create_function_0.source | 3 ++
src/test/regress/regress.c | 50 +++++++++++++++++++++
src/test/regress/sql/conversion.sql | 3 ++
7 files changed, 121 insertions(+), 2 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Andres Freund 2025-02-10 17:30:44 pgsql: Fix type in test_escape test
Previous Message Andres Freund 2025-02-10 15:09:48 pgsql: Specify the encoding of input to fmtId()