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,24 +34,30 @@ public class JavaVelocityCompressor implements VelocityCompressor {
checkArgument(source.nioBufferCount() == 1, "source 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());
while (!inflater.finished() && inflater.getBytesRead() < source.readableBytes()) {
try {
while (!inflater.finished() && inflater.getBytesWritten() < uncompressedSize) {
if (!destination.isWritable()) {
ensureMaxSize(destination, uncompressedSize);
destination.ensureWritable(ZLIB_BUFFER_SIZE);
}
ByteBuffer destNioBuf = destination.nioBuffer(destination.writerIndex(),
destination.writableBytes());
int produced = inflater.inflate(destNioBuf);
source.readerIndex(origIdx + inflater.getTotalIn());
destination.writerIndex(destination.writerIndex() + produced);
}
if (inflater.getBytesWritten() != uncompressedSize) {
throw new DataFormatException("Did not write the exact expected number of"
+ " uncompressed bytes, expected " + uncompressedSize);
}
source.readerIndex(origIdx + inflater.getTotalIn());
} finally {
inflater.reset();
}
}
@Override
public void deflate(ByteBuf source, ByteBuf destination) throws DataFormatException {