ASCII Null control character validation

Started by Alexey Chernyshovalmost 9 years ago3 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

won't retrysuccessCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t37797
psql -h localhost -U postgres

Built from patchset v1 (message #1), July 27, 2026 at 09:41 PM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t37797_1 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t37797_1 && git checkout t37797_1

Patchset v1 (message #1) is on t37797_1

Jump to latest
#1Alexey Chernyshov
a.chernyshov@postgrespro.ru

Hello, hackers!

I found in src/backend/utils/mb/wchar.c: pg_verify_mbstr_len() that it
reports ASCII Null character (\000) as invalid. As for me, it should
pass validation. However, ASCII Null character breaks a line and the
end of the line is missed, try:

INSERT INTO mytable VALUES (E'a\001b\000c and rest of line MIA');

Find patch attached. Am I wrong?

--
Alexey Chernyshov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

Attachments:

t37797_1
0001-Fix-0x00-symbol-validation.patchtext/x-patchDownload+5-12
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Alexey Chernyshov (#1)
Re: ASCII Null control character validation

Alexey Chernyshov <a.chernyshov@postgrespro.ru> writes:

I found in src/backend/utils/mb/wchar.c: pg_verify_mbstr_len() that it
reports ASCII Null character (\000) as invalid. As for me, it should
pass validation.

This is intentional and we're not going to change it. There is too
much code in the backend that relies on NUL-terminated strings ...

However, ASCII Null character breaks a line and the
end of the line is missed, try:
INSERT INTO mytable VALUES (E'a\001b\000c and rest of line MIA');

... like that for instance. See (many) past discussions of this issue.

regards, tom lane

#3Peter Eisentraut
peter_e@gmx.net
In reply to: Alexey Chernyshov (#1)
Re: ASCII Null control character validation

On 11/30/17 03:13, Alexey Chernyshov wrote:

I found in src/backend/utils/mb/wchar.c: pg_verify_mbstr_len() that it
reports ASCII Null character (\000) as invalid. As for me, it should
pass validation. However, ASCII Null character breaks a line and the
end of the line is missed, try:

INSERT INTO mytable VALUES (E'a\001b\000c and rest of line MIA');

Find patch attached. Am I wrong?

The main reason why you can't usefully have null characters in a string
literal is that the type input functions take a cstring as input, so no
string with a null character can possibly be input to a type.

So removing that check would just cause failure or confusion later.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services