From e136fada5d9084e0adc115f37c740bc0a777ca4a Mon Sep 17 00:00:00 2001 From: Bjarne Koll Date: Mon, 29 Apr 2024 05:43:50 +0200 Subject: [PATCH] Validate manifest provided mapping namespace (#10612) With plugins adopting paperweights mapping namespaces in their manifest file in and after paper 1.20.5, incorrectly spelled namespaces previously were simply implied as the spigot namespace. This commit properly ensures plugin authors are using a known mapping namespace in their manifest, avoiding down the line confusion on incorrect remapping behaviour. The commit also fixes two incorrect log parameters. --- patches/server/Plugin-remapping.patch | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/patches/server/Plugin-remapping.patch b/patches/server/Plugin-remapping.patch index 6bb3f1573b..01bb86d1b8 100644 --- a/patches/server/Plugin-remapping.patch +++ b/patches/server/Plugin-remapping.patch @@ -313,6 +313,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +import java.io.IOException; +import java.util.Collection; +import java.util.List; ++import java.util.Set; +import java.util.jar.Attributes; +import java.util.jar.Manifest; +import net.neoforged.art.api.Transformer; @@ -322,6 +323,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + static final String MOJANG_NAMESPACE = "mojang"; + static final String MOJANG_PLUS_YARN_NAMESPACE = "mojang+yarn"; + static final String SPIGOT_NAMESPACE = "spigot"; ++ static final Set KNOWN_NAMESPACES = Set.of(MOJANG_NAMESPACE, MOJANG_PLUS_YARN_NAMESPACE, SPIGOT_NAMESPACE); + + private final String mainAttributesKey; + private final String namespace; @@ -502,7 +504,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + for (final Path lib : libraries) { + if (!lib.getFileName().toString().endsWith(".jar")) { + if (DEBUG_LOGGING) { -+ LOGGER.info("Library '{}' is not a jar.", libraries); ++ LOGGER.info("Library '{}' is not a jar.", lib); + } + tasks.add(CompletableFuture.completedFuture(lib)); + continue; @@ -510,7 +512,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + final @Nullable Path cached = this.libraries.getIfPresent(lib); + if (cached != null) { + if (DEBUG_LOGGING) { -+ LOGGER.info("Library '{}' has not changed since last remap.", libraries); ++ LOGGER.info("Library '{}' has not changed since last remap.", lib); + } + tasks.add(CompletableFuture.completedFuture(cached)); + continue; @@ -681,6 +683,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + } else { + ns = null; + } ++ ++ if (ns != null && !InsertManifestAttribute.KNOWN_NAMESPACES.contains(ns)) { ++ throw new RuntimeException("Failed to remap plugin " + inputFile + " with unknown mapping namespace '" + ns + "'"); ++ } ++ + final boolean mojangMappedManifest = ns != null && (ns.equals(InsertManifestAttribute.MOJANG_NAMESPACE) || ns.equals(InsertManifestAttribute.MOJANG_PLUS_YARN_NAMESPACE)); + if (library) { + if (mojangMappedManifest) {