Checking that payload length is positive on packets reading (#1211)

This commit is contained in:
Konstantin Shandurenko 2022-07-07 05:18:24 +03:00 committed by GitHub
parent 4884051c6a
commit 0c6599fee6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -172,6 +172,9 @@ public final class PacketUtils {
if (compressed) {
final int dataLength = readBuffer.readVarInt();
final int payloadLength = packetLength - (readBuffer.readerOffset() - readerStart);
if (payloadLength < 0) {
throw new DataFormatException("Negative payload length " + payloadLength);
}
if (dataLength == 0) {
// Data is too small to be compressed, payload is following
decompressedSize = payloadLength;