From 06510b6130a1eb5c9bd7f491348860f40147412d Mon Sep 17 00:00:00 2001
From: psolomin
Date: Fri, 28 Apr 2023 12:42:58 +0100
Subject: [PATCH] Fix bug: unnecessary read of data content - corrupt output
---
.../pgclient/impl/codec/CopyOutCommand.java | 1 +
.../impl/codec/CopyOutDataDecoder.java | 2 +-
.../vertx/pgclient/impl/codec/PgDecoder.java | 3 +--
.../vertx/pgclient/PgConnectionCopyTest.java | 20 +++++++++----------
4 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/vertx-pg-client/src/main/java/io/vertx/pgclient/impl/codec/CopyOutCommand.java b/vertx-pg-client/src/main/java/io/vertx/pgclient/impl/codec/CopyOutCommand.java
index 855020687..13170fb2d 100644
--- a/vertx-pg-client/src/main/java/io/vertx/pgclient/impl/codec/CopyOutCommand.java
+++ b/vertx-pg-client/src/main/java/io/vertx/pgclient/impl/codec/CopyOutCommand.java
@@ -22,6 +22,7 @@ public CopyOutCommand(
this.resultHandler = resultHandler;
this.collector = Collector.of(
Buffer::buffer,
+ // TODO: this might be unnecessary slow - think of alternatives
(v, chunk) -> v.appendBuffer(Buffer.buffer(chunk)),
(v1, v2) -> null,
(finalResult) -> finalResult
diff --git a/vertx-pg-client/src/main/java/io/vertx/pgclient/impl/codec/CopyOutDataDecoder.java b/vertx-pg-client/src/main/java/io/vertx/pgclient/impl/codec/CopyOutDataDecoder.java
index 5ca742ec4..320fc13a8 100644
--- a/vertx-pg-client/src/main/java/io/vertx/pgclient/impl/codec/CopyOutDataDecoder.java
+++ b/vertx-pg-client/src/main/java/io/vertx/pgclient/impl/codec/CopyOutDataDecoder.java
@@ -24,7 +24,7 @@ public int size() {
return size;
}
- public void handleChunk(int len, ByteBuf in) {
+ public void handleChunk(ByteBuf in) {
if (failure != null) {
return;
}
diff --git a/vertx-pg-client/src/main/java/io/vertx/pgclient/impl/codec/PgDecoder.java b/vertx-pg-client/src/main/java/io/vertx/pgclient/impl/codec/PgDecoder.java
index f9c951e4c..eb58ff342 100644
--- a/vertx-pg-client/src/main/java/io/vertx/pgclient/impl/codec/PgDecoder.java
+++ b/vertx-pg-client/src/main/java/io/vertx/pgclient/impl/codec/PgDecoder.java
@@ -475,8 +475,7 @@ private void decodeCopyOutResponse(ChannelHandlerContext ctx, ByteBuf in) {}
private void decodeCopyData(ChannelHandlerContext ctx, ByteBuf in) {
PgCommandCodec, ?> codec = inflight.peek();
CopyOutCommandCodec cmdCodec = (CopyOutCommandCodec) codec;
- int len = in.readUnsignedShort();
- cmdCodec.decoder.handleChunk(len, in);
+ cmdCodec.decoder.handleChunk(in);
}
private void decodeCopyCompletion(ChannelHandlerContext ctx, ByteBuf in) {}
diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/PgConnectionCopyTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/PgConnectionCopyTest.java
index 8b2ce3e85..67579a901 100644
--- a/vertx-pg-client/src/test/java/io/vertx/pgclient/PgConnectionCopyTest.java
+++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/PgConnectionCopyTest.java
@@ -50,16 +50,16 @@ public void testCopyToCsvBytes(TestContext ctx) {
ctx.assertEquals(10, result.size());
ctx.assertEquals(
Buffer.buffer(
- "Whatever-0\n" +
- "Whatever-1\n" +
- "Whatever-2\n" +
- "Whatever-3\n" +
- "Whatever-4\n" +
- "Whatever-5\n" +
- "Whatever-6\n" +
- "Whatever-7\n" +
- "Whatever-8\n" +
- "Whatever-9\n"
+ "0,Whatever-0\n" +
+ "1,Whatever-1\n" +
+ "2,Whatever-2\n" +
+ "3,Whatever-3\n" +
+ "4,Whatever-4\n" +
+ "5,Whatever-5\n" +
+ "6,Whatever-6\n" +
+ "7,Whatever-7\n" +
+ "8,Whatever-8\n" +
+ "9,Whatever-9\n"
),
result.value()
);