Skip to content

Commit

Permalink
Add system property to permit oversized packets.
Browse files Browse the repository at this point in the history
This should fix #91, but this is not enabled by default for security reasons. This also does not raise all relevant packet lengths capped by the protocol, although this can be added at a future point in time.

With this system property enabled, Krypton permits packets with 5-byte VarInt prefixes and allows uncompressed packets to be up to 2GiB in size.
  • Loading branch information
astei committed Sep 11, 2023
1 parent 545721a commit 5fb9eba
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import io.netty.util.ByteProcessor;

public class VarintByteDecoder implements ByteProcessor {

private static final int MAXIMUM_VARINT_BYTE_SIZE = Boolean.getBoolean("krypton.permit-oversized-packets")
? 5 : 3;

private int readVarint;
private int bytesRead;
private DecodeResult result = DecodeResult.TOO_SHORT;
Expand All @@ -18,7 +22,7 @@ public boolean process(byte k) {
return false;
}
readVarint |= (k & 0x7F) << bytesRead++ * 7;
if (bytesRead > 3) {
if (bytesRead > MAXIMUM_VARINT_BYTE_SIZE) {
result = DecodeResult.TOO_BIG;
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

public class MinecraftCompressDecoder extends ByteToMessageDecoder {

private static final int UNCOMPRESSED_CAP = 8 * 1024 * 1024; // 8MiB
private static final int UNCOMPRESSED_CAP = Boolean.getBoolean("krypton.permit-oversized-packets")
? Integer.MAX_VALUE : 8 * 1024 * 1024;

private int threshold;
private final boolean validate;
Expand Down

0 comments on commit 5fb9eba

Please sign in to comment.