2023-09-24 01:22:13 +02:00
From b34e416dfd250b7d97c1ad1c810016203d9e53ab Mon Sep 17 00:00:00 2001
2016-05-28 18:34:39 +02:00
From: Techcable <Techcable@techcable.net>
Date: Fri, 18 Mar 2016 10:53:24 -0700
Subject: [PATCH] Better Decompression Sanity
Fixes #40
diff --git a/proxy/src/main/java/net/md_5/bungee/compress/PacketDecompressor.java b/proxy/src/main/java/net/md_5/bungee/compress/PacketDecompressor.java
2021-06-13 17:48:27 +02:00
index 445ee947..eaedf4bc 100644
2016-05-28 18:34:39 +02:00
--- a/proxy/src/main/java/net/md_5/bungee/compress/PacketDecompressor.java
+++ b/proxy/src/main/java/net/md_5/bungee/compress/PacketDecompressor.java
@@ -1,5 +1,7 @@
package net.md_5.bungee.compress;
+import lombok.*;
+
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
@@ -8,9 +10,11 @@ import java.util.List;
import net.md_5.bungee.jni.zlib.BungeeZlib;
import net.md_5.bungee.protocol.DefinedPacket;
+@RequiredArgsConstructor
public class PacketDecompressor extends MessageToMessageDecoder<ByteBuf>
{
+ private final int compressionThreshold;
private final BungeeZlib zlib = CompressFactory.zlib.newInstance();
@Override
2021-06-13 17:48:27 +02:00
@@ -34,12 +38,13 @@ public class PacketDecompressor extends MessageToMessageDecoder<ByteBuf>
out.add( in.retain() );
2016-05-28 18:34:39 +02:00
} else
{
+ Preconditions.checkArgument( size >= compressionThreshold, "Decompressed size %s less than compression threshold %s", size, compressionThreshold);
ByteBuf decompressed = ctx.alloc().directBuffer();
try
{
zlib.process( in, decompressed );
- Preconditions.checkState( decompressed.readableBytes() == size, "Decompressed packet size mismatch" );
+ Preconditions.checkArgument( decompressed.readableBytes() == size, "Decompressed size %s is not equal to actual decompressed bytes", size, decompressed.readableBytes());
out.add( decompressed );
decompressed = null;
diff --git a/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java b/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java
2023-09-24 01:22:13 +02:00
index e8d5ed19..00e03bae 100644
2016-05-28 18:34:39 +02:00
--- a/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java
+++ b/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java
2023-09-24 01:22:13 +02:00
@@ -181,7 +181,7 @@ public class ChannelWrapper
2016-05-28 18:34:39 +02:00
2023-09-21 12:33:23 +02:00
if ( ch.pipeline().get( PacketDecompressor.class ) == null && compressionThreshold >= 0 )
2016-05-28 18:34:39 +02:00
{
- addBefore( PipelineUtils.PACKET_DECODER, "decompress", new PacketDecompressor() );
+ addBefore( PipelineUtils.PACKET_DECODER, "decompress", new PacketDecompressor(compressionThreshold) );
}
2023-09-21 12:33:23 +02:00
if ( compressionThreshold < 0 )
2016-05-28 18:34:39 +02:00
{
--
2023-09-24 01:22:13 +02:00
2.34.1
2016-05-28 18:34:39 +02:00