Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit fc36ac5

Browse files
committed
Fix COPY FROM when database encoding is SQL_ASCII.
In the codepath when no encoding conversion is required, the check for incomplete character at the end of input incorrectly used server encoding's max character length, instead of the client's. Usually the server and client encodings are the same when we're not performing encoding conversion, but SQL_ASCII is an exception. In the passing, also fix some outdated comments that still talked about the old COPY protocol. It was removed in v14. Per bug #17501 from Vitaly Voronov. Backpatch to v14 where this was introduced. Discussion: https://www.postgresql.org/message-id/17501-128b1dd039362ae6@postgresql.org
1 parent f6b6a8f commit fc36ac5

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

src/backend/commands/copyfromparse.c

+7-12
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ CopyConvertBuf(CopyFromState cstate)
444444
* least one character, and a failure to do so means that we've
445445
* hit an invalid byte sequence.
446446
*/
447-
if (cstate->raw_reached_eof || unverifiedlen >= pg_database_encoding_max_length())
447+
if (cstate->raw_reached_eof || unverifiedlen >= pg_encoding_max_length(cstate->file_encoding))
448448
cstate->input_reached_error = true;
449449
return;
450450
}
@@ -1172,14 +1172,12 @@ CopyReadLineText(CopyFromState cstate)
11721172
char c;
11731173

11741174
/*
1175-
* Load more data if needed. Ideally we would just force four bytes
1176-
* of read-ahead and avoid the many calls to
1177-
* IF_NEED_REFILL_AND_NOT_EOF_CONTINUE(), but the COPY_OLD_FE protocol
1178-
* does not allow us to read too far ahead or we might read into the
1179-
* next data, so we read-ahead only as far we know we can. One
1180-
* optimization would be to read-ahead four byte here if
1181-
* cstate->copy_src != COPY_OLD_FE, but it hardly seems worth it,
1182-
* considering the size of the buffer.
1175+
* Load more data if needed.
1176+
*
1177+
* TODO: We could just force four bytes of read-ahead and avoid the
1178+
* many calls to IF_NEED_REFILL_AND_NOT_EOF_CONTINUE(). That was
1179+
* unsafe with the old v2 COPY protocol, but we don't support that
1180+
* anymore.
11831181
*/
11841182
if (input_buf_ptr >= copy_buf_len || need_data)
11851183
{
@@ -1214,9 +1212,6 @@ CopyReadLineText(CopyFromState cstate)
12141212
* Force fetch of the next character if we don't already have it.
12151213
* We need to do this before changing CSV state, in case one of
12161214
* these characters is also the quote or escape character.
1217-
*
1218-
* Note: old-protocol does not like forced prefetch, but it's OK
1219-
* here since we cannot validly be at EOF.
12201215
*/
12211216
if (c == '\\' || c == '\r')
12221217
{

0 commit comments

Comments
 (0)