Add pg_encoding_set_invalid()
authorAndres Freund
Mon, 10 Feb 2025 15:03:37 +0000 (10:03 -0500)
committerAndres Freund
Mon, 10 Feb 2025 15:03:37 +0000 (10:03 -0500)
commit4dc28963533704fc7dd922b9447467466a233d89
treea4369935580c83902e9b85bd09c7d794a015878a
parent3d17d7d7fb7a4603b48acb275b5a416f110db464
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 
Reviewed-by: Andres Freund
Backpatch-through: 13
Security: CVE-2025-1094
src/common/wchar.c
src/include/mb/pg_wchar.h
src/test/regress/expected/conversion.out
src/test/regress/regress.c
src/test/regress/sql/conversion.sql