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.
This commit is contained in:
Bjarne Koll 2024-05-12 17:41:21 +02:00 committed by GitHub
parent 7e48f66c05
commit f041f48458
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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;
+ }
+