Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-16 21:10:30 +01:00
Further improve the inflate overflow checks in the Java 11 compressor native
This brings the Java compressor in line with our libdeflate one. Backport this from Velocity 2.0.0.
Dieser Commit ist enthalten in:
Ursprung
1f5b0e1e03
Commit
91b295ead5
@ -66,7 +66,7 @@ public class Java11VelocityCompressor implements VelocityCompressor {
|
|||||||
final int origIdx = source.readerIndex();
|
final int origIdx = source.readerIndex();
|
||||||
INFLATE_SET_INPUT.invokeExact(inflater, source.nioBuffer());
|
INFLATE_SET_INPUT.invokeExact(inflater, source.nioBuffer());
|
||||||
|
|
||||||
while (!inflater.finished() && inflater.getBytesRead() < source.readableBytes()) {
|
while (!inflater.finished() && inflater.getBytesWritten() < uncompressedSize) {
|
||||||
if (!destination.isWritable()) {
|
if (!destination.isWritable()) {
|
||||||
ensureMaxSize(destination, uncompressedSize);
|
ensureMaxSize(destination, uncompressedSize);
|
||||||
destination.ensureWritable(ZLIB_BUFFER_SIZE);
|
destination.ensureWritable(ZLIB_BUFFER_SIZE);
|
||||||
@ -78,13 +78,18 @@ public class Java11VelocityCompressor implements VelocityCompressor {
|
|||||||
destination.writerIndex(destination.writerIndex() + produced);
|
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());
|
source.readerIndex(origIdx + inflater.getTotalIn());
|
||||||
inflater.reset();
|
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
if (e instanceof DataFormatException) {
|
if (e instanceof DataFormatException) {
|
||||||
throw (DataFormatException) e;
|
throw (DataFormatException) e;
|
||||||
}
|
}
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
} finally {
|
||||||
|
inflater.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren