From 0c6599fee6e77795d703c1355cd275b41a32388b Mon Sep 17 00:00:00 2001 From: Konstantin Shandurenko Date: Thu, 7 Jul 2022 05:18:24 +0300 Subject: [PATCH] Checking that payload length is positive on packets reading (#1211) --- src/main/java/net/minestom/server/utils/PacketUtils.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/net/minestom/server/utils/PacketUtils.java b/src/main/java/net/minestom/server/utils/PacketUtils.java index f3e33007d..12f72b697 100644 --- a/src/main/java/net/minestom/server/utils/PacketUtils.java +++ b/src/main/java/net/minestom/server/utils/PacketUtils.java @@ -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;