From ce132b15d53fa8418627bc1006cf6cbea812eb1b Mon Sep 17 00:00:00 2001 From: Andrey Mizurov Date: Fri, 21 Aug 2020 10:18:48 +0300 Subject: [PATCH] Small fix that takes into account the remainder when assigning the size (see #10453) (#10491) Motivation: This is small fixes for #10453 PR according @njhill and @normanmaurer conversation. Modification: Simple refactor and takes into account remainder when calculate size. Result: Behavior is correct --- .../codec/http/multipart/AbstractDiskHttpData.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/multipart/AbstractDiskHttpData.java b/codec-http/src/main/java/io/netty/handler/codec/http/multipart/AbstractDiskHttpData.java index 61397967f5..b3fe49db89 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/multipart/AbstractDiskHttpData.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/multipart/AbstractDiskHttpData.java @@ -161,21 +161,21 @@ public abstract class AbstractDiskHttpData extends AbstractHttpData { RandomAccessFile accessFile = new RandomAccessFile(file, "rw"); fileChannel = accessFile.getChannel(); } - int totalWritten = 0; + int remaining = localsize; long position = fileChannel.position(); int index = buffer.readerIndex(); - while (totalWritten < localsize) { - int written = buffer.getBytes(index, fileChannel, position, localsize - totalWritten); + while (remaining > 0) { + int written = buffer.getBytes(index, fileChannel, position, remaining); if (written < 0) { break; } - totalWritten += written; + remaining -= written; position += written; index += written; } fileChannel.position(position); buffer.readerIndex(index); - size += localsize; + size += localsize - remaining; } finally { // Release the buffer as it was retained before and we not need a reference to it at all // See https://github.com/netty/netty/issues/1516