From 7bd424ec429d8c1b0d2d37f0472ceccee150907b Mon Sep 17 00:00:00 2001 From: Maschell Date: Sun, 7 Apr 2019 14:53:35 +0200 Subject: [PATCH] Fix a bug in the "getChunkOfStream" function --- src/de/mas/wiiu/jnus/utils/StreamUtils.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/de/mas/wiiu/jnus/utils/StreamUtils.java b/src/de/mas/wiiu/jnus/utils/StreamUtils.java index 23486c7..a509554 100644 --- a/src/de/mas/wiiu/jnus/utils/StreamUtils.java +++ b/src/de/mas/wiiu/jnus/utils/StreamUtils.java @@ -88,8 +88,17 @@ public final class StreamUtils { System.arraycopy(overflowbuf, 0, output, inBlockBuffer, toRead); inBlockBuffer += toRead; - System.arraycopy(overflowbuf, toRead, overflowbuf, 0, tooMuch); - overflowbuffer.setLengthOfDataInBuffer(tooMuch); + if (tooMuch > 0) { + System.arraycopy(overflowbuf, toRead, overflowbuf, 0, tooMuch); + overflowbuffer.setLengthOfDataInBuffer(tooMuch); + } else { + // Moving into front. + int missingLength = overflowbuffer.getLengthOfDataInBuffer() - toRead; + if (missingLength > 0) { + System.arraycopy(overflowbuf, toRead, overflowbuf, 0, missingLength); + overflowbuffer.setLengthOfDataInBuffer(missingLength); + } + } } else { System.arraycopy(overflowbuf, 0, output, inBlockBuffer, overflowbuffer.getLengthOfDataInBuffer()); inBlockBuffer += overflowbuffer.getLengthOfDataInBuffer();