Waterfall/BungeeCord-Patches/0023-Better-Decompression-Sanity.patch
Shane Freeder d598d51135
Updated Upstream (BungeeCord)
Upstream has released updates that appears to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

BungeeCord Changes:
85ea4c16 Remove redundant scheduled close, already channel closed by future.
22d2cd33 #2747: Fix TranslatableComponent.deserialize()
2020-01-15 00:04:50 +00:00

63 lines
2.7 KiB
Diff

From 3e59f82613e4f183eebc4717f1fe73d5049a9d27 Mon Sep 17 00:00:00 2001
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
index 21b3ea2b..37fe6ac7 100644
--- 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
@@ -35,12 +39,13 @@ public class PacketDecompressor extends MessageToMessageDecoder<ByteBuf>
in.skipBytes( in.readableBytes() );
} 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
index 0ef21887..30ccfa9f 100644
--- a/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java
+++ b/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java
@@ -138,7 +138,7 @@ public class ChannelWrapper
if ( ch.pipeline().get( PacketDecompressor.class ) == null && compressionThreshold != -1 )
{
- addBefore( PipelineUtils.PACKET_DECODER, "decompress", new PacketDecompressor() );
+ addBefore( PipelineUtils.PACKET_DECODER, "decompress", new PacketDecompressor(compressionThreshold) );
}
if ( compressionThreshold == -1 )
{
--
2.24.1