Waterfall/Waterfall-Proxy-Patches/0011-Packet-Checks.patch

54 lines
2.2 KiB
Diff
Raw Normal View History

2022-12-22 01:56:04 +01:00
From cf87130274644325adbf7fabb7b95d95e976ee57 Mon Sep 17 00:00:00 2001
2020-12-16 11:14:44 +01:00
From: foss-mc <69294560+foss-mc@users.noreply.github.com>
Date: Wed, 16 Dec 2020 18:10:30 +0800
Subject: [PATCH] Packet Checks
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java b/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java
2022-12-22 01:56:04 +01:00
index c31ec1ce7..640f0ea26 100644
2020-12-16 11:14:44 +01:00
--- a/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/MinecraftDecoder.java
2021-02-26 02:46:21 +01:00
@@ -38,6 +38,19 @@ public class MinecraftDecoder extends MessageToMessageDecoder<ByteBuf>
2020-12-16 11:14:44 +01:00
}
Protocol.DirectionData prot = ( server ) ? protocol.TO_SERVER : protocol.TO_CLIENT;
2022-12-22 01:56:04 +01:00
+
2020-12-16 11:14:44 +01:00
+ // FlameCord - Check size before decoding
+ if (prot == protocol.TO_SERVER) {
+ final int readableBytes = in.readableBytes();
+ final int capacity = in.capacity();
+
+ if (readableBytes > 2097152) {
+ throw new FastDecoderException("Error decoding packet with too many readableBytes: " + readableBytes);
+ } else if (capacity > 2097152) {
+ throw new FastDecoderException("Error decoding packet with too big capacity: " + capacity);
+ }
+ }
+
2022-12-22 01:56:04 +01:00
ByteBuf slice = in.duplicate(); // FlameCord - Duplicate buf instead of Copy
2020-12-16 11:14:44 +01:00
Object packetTypeInfo = null;
2020-12-16 11:44:19 +01:00
diff --git a/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java b/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java
2022-12-22 01:56:04 +01:00
index 29cf4b4fc..4820267b3 100644
2020-12-16 11:44:19 +01:00
--- a/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java
+++ b/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java
2021-10-07 05:06:05 +02:00
@@ -78,6 +78,15 @@ public class HandlerBoss extends ChannelInboundHandlerAdapter
2020-12-16 11:44:19 +01:00
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
{
+ // FlameCord - Return if channel isn't active
+ if (!ctx.channel().isActive()) {
2021-10-07 05:06:05 +02:00
+ if (msg instanceof PacketWrapper) {
+ ((PacketWrapper) msg).trySingleRelease();
+ }
+
2020-12-16 11:44:19 +01:00
+ return;
+ }
+
if ( msg instanceof HAProxyMessage )
{
HAProxyMessage proxy = (HAProxyMessage) msg;
2020-12-16 11:14:44 +01:00
--
2022-12-22 01:56:04 +01:00
2.37.3.windows.1
2020-12-16 11:14:44 +01:00