]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix backslash-escaping multibyte chars in COPY FROM.
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Fri, 5 Feb 2021 09:14:56 +0000 (11:14 +0200)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Fri, 5 Feb 2021 09:17:07 +0000 (11:17 +0200)
commitc06632e48b3537f9a062f6c4686a730625a429fd
tree24c6bef58b50498c2bccf07b7484b3c9b030c86b
parent2671125c75c04f7abc4a87998959c197e99e34c6
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
src/backend/commands/copy.c