From 55a16d8581eb18fd32d028ae1ac783eb3d4687ac Mon Sep 17 00:00:00 2001 From: Shane Freeder Date: Tue, 22 Nov 2022 17:50:31 +0000 Subject: [PATCH] Fix Varint21FrameDecoder cached length buf usage --- ...0-Optimize-NetworkManager-Exception-Handling.patch | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/patches/server/0450-Optimize-NetworkManager-Exception-Handling.patch b/patches/server/0450-Optimize-NetworkManager-Exception-Handling.patch index cf2905d1e..3ae0daa7d 100644 --- a/patches/server/0450-Optimize-NetworkManager-Exception-Handling.patch +++ b/patches/server/0450-Optimize-NetworkManager-Exception-Handling.patch @@ -17,10 +17,10 @@ index 672e296cec289abd3bf797d84e16983ca50907be..aec921477e035095d569eab3335175b9 return function != null ? function.apply(buf) : null; } diff --git a/src/main/java/net/minecraft/network/Varint21FrameDecoder.java b/src/main/java/net/minecraft/network/Varint21FrameDecoder.java -index 99b581052f937b0f2d6b5d73de699008c1d51774..ed54479b14dcfc736ac90749106557f0ff537550 100644 +index 99b581052f937b0f2d6b5d73de699008c1d51774..81ec2011a93bb94200ad750f4666ba1cd8be11c5 100644 --- a/src/main/java/net/minecraft/network/Varint21FrameDecoder.java +++ b/src/main/java/net/minecraft/network/Varint21FrameDecoder.java -@@ -8,8 +8,20 @@ import io.netty.handler.codec.CorruptedFrameException; +@@ -8,9 +8,20 @@ import io.netty.handler.codec.CorruptedFrameException; import java.util.List; public class Varint21FrameDecoder extends ByteToMessageDecoder { @@ -34,13 +34,14 @@ index 99b581052f937b0f2d6b5d73de699008c1d51774..ed54479b14dcfc736ac90749106557f0 + } + // Paper end byteBuf.markReaderIndex(); +- byte[] bs = new byte[3]; + // Paper start - reuse temporary length buffer -+ byte[] abyte = lenBuf; -+ java.util.Arrays.fill(abyte, (byte) 0); ++ byte[] bs = lenBuf; ++ java.util.Arrays.fill(bs, (byte) 0); + // Paper end - byte[] bs = new byte[3]; for(int i = 0; i < bs.length; ++i) { + if (!byteBuf.isReadable()) { diff --git a/src/main/java/net/minecraft/network/protocol/PacketUtils.java b/src/main/java/net/minecraft/network/protocol/PacketUtils.java index 049e64c355d5f064009b1107ad15d28c44f999dd..acfa1907bfc9c29d261cfccc00d65bad9ad1a002 100644 --- a/src/main/java/net/minecraft/network/protocol/PacketUtils.java