From b6824faf03d4d4bdb909b33230fab0011cbcfc69 Mon Sep 17 00:00:00 2001 From: Joel Jacobson Date: Sun, 10 Nov 2024 22:18:48 +0100 Subject: [PATCH] psql: Make \copy from 'text' and 'csv' formats fail on NUL bytes When using \copy from in psql to import files containing NUL bytes (\0) in 'text' or 'csv' format, the NUL bytes were not detected and did not result in an error, leading to silent data corruption. This behavior is inconsistent with server-side COPY FROM, which reports an error upon encountering NUL bytes in the 'text' and 'csv' formats. Fix by adjusting handleCopyIn() to use the binary code path also when the copy source is a file (i.e., copystream != pset.cur_cmd_source), even in textual copies. This ensures that NUL bytes are detected and reported in the same way as server-side COPY. --- src/bin/psql/copy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.c index e020e4d665d..306f5161e1d 100644 --- a/src/bin/psql/copy.c +++ b/src/bin/psql/copy.c @@ -544,7 +544,7 @@ handleCopyIn(PGconn *conn, FILE *copystream, bool isbinary, PGresult **res) OK = true; - if (isbinary) + if (isbinary || copystream != pset.cur_cmd_source) { /* interactive input probably silly, but give one prompt anyway */ if (showprompt) -- 2.45.1