Waterfall/BungeeCord-Patches/0044-Don-t-use-a-bytebuf-for-packet-decoding.patch
_tomcraft 85c0a35f0b
Updated Upstream (BungeeCord) (#695)
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:
6613aaea Add test fix for library classes being visible to non-dependent plugins
53ce6b93 #3200: Fix protocol for 21w40a
d8e29384 #2466: Use switch in "BungeeCord" plugin message handling
5cf869df #3198: Remove terminally deprecated SecurityManager
f26f7d88 Add optional 1.18 (21w40a) snapshot protocol support
2021-10-09 10:43:12 +01:00

72 lines
2.8 KiB
Diff

From 8610fad68f5719f52367f7f2067fde61b2c806c8 Mon Sep 17 00:00:00 2001
From: creeper123123321 <creeper123123321@gmail.com>
Date: Thu, 17 Jan 2019 03:25:59 +0000
Subject: [PATCH] Don't use a bytebuf for packet decoding
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Varint21FrameDecoder.java b/protocol/src/main/java/net/md_5/bungee/protocol/Varint21FrameDecoder.java
index f297620c..c0d37142 100644
--- a/protocol/src/main/java/net/md_5/bungee/protocol/Varint21FrameDecoder.java
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/Varint21FrameDecoder.java
@@ -27,8 +27,7 @@ public class Varint21FrameDecoder extends ByteToMessageDecoder
in.markReaderIndex();
- final byte[] buf = new byte[ 3 ];
- for ( int i = 0; i < buf.length; i++ )
+ for ( int i = 0; i < 3; i++ ) // Waterfall
{
if ( !in.isReadable() )
{
@@ -36,10 +35,13 @@ public class Varint21FrameDecoder extends ByteToMessageDecoder
return;
}
- buf[i] = in.readByte();
- if ( buf[i] >= 0 )
+ // Waterfall start
+ byte read = in.readByte();
+ if ( read >= 0 )
{
- int length = DefinedPacket.readVarInt( Unpooled.wrappedBuffer( buf ) );
+ in.resetReaderIndex();
+ int length = DefinedPacket.readVarInt( in );
+ // Waterfall end
if ( false && length == 0) // Waterfall - ignore
{
throw new CorruptedFrameException( "Empty Packet!" );
@@ -49,26 +51,11 @@ public class Varint21FrameDecoder extends ByteToMessageDecoder
{
in.resetReaderIndex();
return;
- } else
- {
- if ( in.hasMemoryAddress() )
- {
- out.add( in.slice( in.readerIndex(), length ).retain() );
- in.skipBytes( length );
- } else
- {
- if ( !DIRECT_WARNING )
- {
- DIRECT_WARNING = true;
- System.out.println( "Netty is not using direct IO buffers." );
- }
-
- // See https://github.com/SpigotMC/BungeeCord/issues/1717
- ByteBuf dst = ctx.alloc().directBuffer( length );
- in.readBytes( dst );
- out.add( dst );
- }
+ // Waterfall start
+ } else {
+ out.add(in.readRetainedSlice(length));
return;
+ // Waterfall end
}
}
}
--
2.30.1 (Apple Git-130)