From b0736548a9c954d3fa73f121b5ce6e2c474ba6d4 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sun, 9 Jun 2019 04:43:24 -0400 Subject: [PATCH] Strengthen check in JavaVelocityCompressor --- .../natives/compression/JavaVelocityCompressor.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/native/src/main/java/com/velocitypowered/natives/compression/JavaVelocityCompressor.java b/native/src/main/java/com/velocitypowered/natives/compression/JavaVelocityCompressor.java index 416a5e6fa..633fc4f1d 100644 --- a/native/src/main/java/com/velocitypowered/natives/compression/JavaVelocityCompressor.java +++ b/native/src/main/java/com/velocitypowered/natives/compression/JavaVelocityCompressor.java @@ -28,16 +28,16 @@ public class JavaVelocityCompressor implements VelocityCompressor { public void inflate(ByteBuf source, ByteBuf destination, int max) throws DataFormatException { ensureNotDisposed(); + final int available = source.readableBytes(); if (source.hasArray()) { - inflater.setInput(source.array(), source.arrayOffset() + source.readerIndex(), - source.readableBytes()); + inflater.setInput(source.array(), source.arrayOffset() + source.readerIndex(), available); } else { - byte[] inData = new byte[source.readableBytes()]; + byte[] inData = new byte[available]; source.readBytes(inData); inflater.setInput(inData); } - while (!inflater.finished()) { + while (!inflater.finished() && inflater.getBytesRead() < available) { ensureMaxSize(destination, max); int read = inflater.inflate(buf); destination.writeBytes(buf, 0, read);