diff --git a/src/backend/commands/copyfromparse.c b/src/backend/commands/copyfromparse.c
index a280efe23f..2ea9679b3c 100644
--- a/src/backend/commands/copyfromparse.c
+++ b/src/backend/commands/copyfromparse.c
@@ -1426,13 +1426,17 @@ CopyReadLineText(CopyFromState cstate)
 				}
 
 				/*
-				 * Transfer only the data before the \. into line_buf, then
-				 * discard the data and the \. sequence.
+				 * If there is any data on this line before the \., complain.
+				 */
+				if (cstate->line_buf.len > 0 ||
+					prev_raw_ptr > cstate->input_buf_index)
+					ereport(ERROR,
+							(errcode(ERRCODE_BAD_COPY_FILE_FORMAT),
+							 errmsg("end-of-copy marker corrupt")));
+
+				/*
+				 * Discard the \. and newline, then report EOF.
 				 */
-				if (prev_raw_ptr > cstate->input_buf_index)
-					appendBinaryStringInfo(&cstate->line_buf,
-										   cstate->input_buf + cstate->input_buf_index,
-										   prev_raw_ptr - cstate->input_buf_index);
 				cstate->input_buf_index = input_buf_ptr;
 				result = true;	/* report EOF */
 				break;
