From f041f48458e6d81a54895e988867c0b738922d4d Mon Sep 17 00:00:00 2001 From: Bjarne Koll Date: Sun, 12 May 2024 17:41:21 +0200 Subject: [PATCH] Prevent infinite recursion on cyclic brig redirect (#10705) Prevent infinite recursion when declaring a cyclic relation between command nodes via child nodes redirecting to an nth parent by marking a command node as unwrapped before unwrapping its children. --- patches/server/1048-Brigadier-based-command-API.patch | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/patches/server/1048-Brigadier-based-command-API.patch b/patches/server/1048-Brigadier-based-command-API.patch index e99486deda..b3aa5f1dc0 100644 --- a/patches/server/1048-Brigadier-based-command-API.patch +++ b/patches/server/1048-Brigadier-based-command-API.patch @@ -251,10 +251,10 @@ index dd6012b6a097575b2d1471be5069eccee4537c0a..00000000000000000000000000000000 -} diff --git a/src/main/java/io/papermc/paper/command/brigadier/ApiMirrorRootNode.java b/src/main/java/io/papermc/paper/command/brigadier/ApiMirrorRootNode.java new file mode 100644 -index 0000000000000000000000000000000000000000..2b1cf02f32506187ed0783ae4732ae0f0bdbfc0e +index 0000000000000000000000000000000000000000..23525592d880f340745a28c956fa38d3e4057231 --- /dev/null +++ b/src/main/java/io/papermc/paper/command/brigadier/ApiMirrorRootNode.java -@@ -0,0 +1,252 @@ +@@ -0,0 +1,253 @@ +package io.papermc.paper.command.brigadier; + +import com.google.common.collect.Collections2; @@ -401,6 +401,10 @@ index 0000000000000000000000000000000000000000..2b1cf02f32506187ed0783ae4732ae0f + throw new IllegalArgumentException("Unknown command node passed. Don't know how to unwrap this."); + } + ++ // Store unwrapped node before unwrapping children to avoid infinite recursion in cyclic redirects. ++ converted.wrappedCached = pureNode; ++ pureNode.unwrappedCached = converted; ++ + /* + Add the children to the node, unwrapping each child in the process. + */ @@ -408,9 +412,6 @@ index 0000000000000000000000000000000000000000..2b1cf02f32506187ed0783ae4732ae0f + converted.addChild(this.unwrapNode(child)); + } + -+ converted.wrappedCached = pureNode; -+ pureNode.unwrappedCached = converted; -+ + return converted; + } +