3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-09-29 06:30:16 +02:00

Further improve the inflate overflow checks in the Java compressor native

This brings the Java compressor in line with our libdeflate one.
Dieser Commit ist enthalten in:
Andrew Steinborn 2020-11-05 17:18:41 -05:00
Ursprung 13a63eff76
Commit ace8f7673d

Datei anzeigen

@ -34,23 +34,29 @@ public class JavaVelocityCompressor implements VelocityCompressor {
checkArgument(source.nioBufferCount() == 1, "source has multiple backing buffers"); checkArgument(source.nioBufferCount() == 1, "source has multiple backing buffers");
checkArgument(destination.nioBufferCount() == 1, "destination has multiple backing buffers"); checkArgument(destination.nioBufferCount() == 1, "destination has multiple backing buffers");
int origIdx = source.readerIndex(); final int origIdx = source.readerIndex();
inflater.setInput(source.nioBuffer()); inflater.setInput(source.nioBuffer());
while (!inflater.finished() && inflater.getBytesRead() < source.readableBytes()) { try {
if (!destination.isWritable()) { while (!inflater.finished() && inflater.getBytesWritten() < uncompressedSize) {
ensureMaxSize(destination, uncompressedSize); if (!destination.isWritable()) {
destination.ensureWritable(ZLIB_BUFFER_SIZE); destination.ensureWritable(ZLIB_BUFFER_SIZE);
}
ByteBuffer destNioBuf = destination.nioBuffer(destination.writerIndex(),
destination.writableBytes());
int produced = inflater.inflate(destNioBuf);
destination.writerIndex(destination.writerIndex() + produced);
} }
ByteBuffer destNioBuf = destination.nioBuffer(destination.writerIndex(), if (inflater.getBytesWritten() != uncompressedSize) {
destination.writableBytes()); throw new DataFormatException("Did not write the exact expected number of"
int produced = inflater.inflate(destNioBuf); + " uncompressed bytes, expected " + uncompressedSize);
}
source.readerIndex(origIdx + inflater.getTotalIn()); source.readerIndex(origIdx + inflater.getTotalIn());
destination.writerIndex(destination.writerIndex() + produced); } finally {
inflater.reset();
} }
inflater.reset();
} }
@Override @Override