Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-17 05:20:14 +01: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:
Ursprung
13a63eff76
Commit
ace8f7673d
@ -34,23 +34,29 @@ 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()) {
|
||||
if (!destination.isWritable()) {
|
||||
ensureMaxSize(destination, uncompressedSize);
|
||||
destination.ensureWritable(ZLIB_BUFFER_SIZE);
|
||||
try {
|
||||
while (!inflater.finished() && inflater.getBytesWritten() < uncompressedSize) {
|
||||
if (!destination.isWritable()) {
|
||||
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(),
|
||||
destination.writableBytes());
|
||||
int produced = inflater.inflate(destNioBuf);
|
||||
if (inflater.getBytesWritten() != uncompressedSize) {
|
||||
throw new DataFormatException("Did not write the exact expected number of"
|
||||
+ " uncompressed bytes, expected " + uncompressedSize);
|
||||
}
|
||||
source.readerIndex(origIdx + inflater.getTotalIn());
|
||||
destination.writerIndex(destination.writerIndex() + produced);
|
||||
} finally {
|
||||
inflater.reset();
|
||||
}
|
||||
|
||||
inflater.reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren