pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Heikki Linnakangas <heikki.linnakangas@iki.fi>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix backslash-escaping multibyte chars in COPY FROM.
Date: Fri, 05 Feb 2021 09:58:58 +0000
Message-ID: <E1l7xtC-00068J-6T@gemulon.postgresql.org> (raw)

Fix backslash-escaping multibyte chars in COPY FROM.

If a multi-byte character is escaped with a backslash in TEXT mode input,
and the encoding is one of the client-only encodings where the bytes after
the first one can have an ASCII byte "embedded" in the char, we didn't
skip the character correctly. After a backslash, we only skipped the first
byte of the next character, so if it was a multi-byte character, we would
try to process its second byte as if it was a separate character. If it
was one of the characters with special meaning, like '\n', '\r', or
another '\\', that would cause trouble.

One such exmple is the byte sequence '\x5ca45c2e666f6f' in Big5 encoding.
That's supposed to be [backslash][two-byte character][.][f][o][o], but
because the second byte of the two-byte character is 0x5c, we incorrectly
treat it as another backslash. And because the next character is a dot, we
parse it as end-of-copy marker, and throw an "end-of-copy marker corrupt"
error.

Backpatch to all supported versions.

Reviewed-by: John Naylor, Kyotaro Horiguchi
Discussion: https://www.postgresql.org/message-id/a897f84f-8dca-8798-3139-07da5bb38728%40iki.fi

Branch
------
REL9_6_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/e152ccc7fd5932cfa9371a7c4cb7ca9a7733c5ab

Modified Files
--------------
src/backend/commands/copy.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)



view thread (7+ messages)  latest in thread

Message-ID: <E1l7xtC-00068J-6T@gemulon.postgresql.org>
Permalink:  ../E1l7xtC-00068J-6T@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1l7xtC-00068J-6T@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: heikki.linnakangas@iki.fi
  Subject: Re: pgsql: Fix backslash-escaping multibyte chars in COPY FROM.
  In-Reply-To: <E1l7xtC-00068J-6T@gemulon.postgresql.org>
  References: <E1l7xtC-00068J-6T@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox