From 3d49736b20ffdf64be4a81a42965823279d350b6 Mon Sep 17 00:00:00 2001 From: Gauri Prasad <51212198+gapra-msft@users.noreply.github.com> Date: Mon, 6 Jul 2020 17:06:56 -0700 Subject: [PATCH] Fixes bug in buffered upload where data would be uploaded incorrectly if data did not fit exactly in the buffers (#12832) --- .../storage/common/implementation/UploadBufferPool.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/implementation/UploadBufferPool.java b/sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/implementation/UploadBufferPool.java index 96222f808bd7..b4590afc123e 100644 --- a/sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/implementation/UploadBufferPool.java +++ b/sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/implementation/UploadBufferPool.java @@ -112,10 +112,11 @@ public Flux write(ByteBuffer buf) { // We will overflow the current buffer and require another one. // Duplicate and adjust the window of buf so that we fill up currentBuf without going out of bounds. ByteBuffer duplicate = buf.duplicate(); - duplicate.limit(buf.position() + (int) this.currentBuf.remainingCapacity()); + int newLimit = buf.position() + (int) this.currentBuf.remainingCapacity(); + duplicate.limit(newLimit); this.currentBuf.append(duplicate); // Adjust the window of original buffer to represent remaining part. - buf.position(buf.position() + (int) this.currentBuf.remainingCapacity()); + buf.position(newLimit); result = Flux.just(this.currentBuf);