Skip to content

Commit fab7b39

Browse files
committed
Clear Utf8ByteBufCharsetDecoder#splitCharBuffer once char is complete, close AsyncHttpClient#1357
Motivation: When multiple non US-ASCII chars are split over several chunks, Utf8ByteBufCharsetDecoder crashes with BufferOverflowException. This happens because we don't clear the splitCharBuffer in-between and only do so once decoding is done. Modifications: Clear Utf8ByteBufCharsetDecoder#splitCharBuffer once char is complete Result: No more BufferOverflowException
1 parent bb7652a commit fab7b39

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

netty-utils/src/main/java/org/asynchttpclient/netty/util/Utf8ByteBufCharsetDecoder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,13 @@ private void handleSplitCharBuffer(ByteBuffer nioBuffer, boolean endOfInput) thr
116116
if (res.isError()) {
117117
res.throwException();
118118
}
119+
splitCharBuffer.clear();
119120
}
120121
}
121122

122123
protected void decodePartial(ByteBuffer nioBuffer, boolean endOfInput) throws CharacterCodingException {
123124
// deal with pending splitCharBuffer
124-
if (splitCharBuffer != null && splitCharBuffer.position() > 0 && nioBuffer.hasRemaining()) {
125+
if (splitCharBuffer.position() > 0 && nioBuffer.hasRemaining()) {
125126
handleSplitCharBuffer(nioBuffer, endOfInput);
126127
}
127128

netty-utils/src/test/java/org/asynchttpclient/netty/util/ByteBufUtilsTest.java renamed to netty-utils/src/test/java/org/asynchttpclient/netty/util/Utf8ByteBufCharsetDecoderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import org.testng.annotations.Test;
2222

23-
public class ByteBufUtilsTest {
23+
public class Utf8ByteBufCharsetDecoderTest {
2424

2525
@Test
2626
public void testByteBuf2BytesHasBackingArray() {

0 commit comments

Comments
 (0)