From 13f72076657e175b851c1b5b9a8e0b2a9c6cd50f Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Tue, 18 Oct 2022 19:21:07 -0700 Subject: [PATCH] Add stacktrace deobfuscation in more places (#8484) --- .../api/Add-exception-reporting-event.patch | 3 +- ...nate-Current-redstone-implementation.patch | 4 +- ...ktraces-in-log-messages-crash-report.patch | 86 +++++++++++++++++++ patches/server/EntityMoveEvent.patch | 4 +- ...g-Broken-behavior-of-PlayerJoinEvent.patch | 2 +- patches/server/MC-Utils.patch | 6 +- ...-PlayerChunkMap-adds-crashing-server.patch | 5 +- 7 files changed, 98 insertions(+), 12 deletions(-) diff --git a/patches/api/Add-exception-reporting-event.patch b/patches/api/Add-exception-reporting-event.patch index 89e87d78a6..47a6b652ec 100644 --- a/patches/api/Add-exception-reporting-event.patch +++ b/patches/api/Add-exception-reporting-event.patch @@ -217,6 +217,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 @@ -0,0 +0,0 @@ +package com.destroystokyo.paper.exception; + ++import java.util.logging.Level; +import org.bukkit.Bukkit; +import com.destroystokyo.paper.event.server.ServerExceptionEvent; + @@ -246,7 +247,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + Bukkit.getPluginManager().callEvent(new ServerExceptionEvent(new ServerInternalException(cause))); + ; + } catch (Throwable t) { -+ t.printStackTrace(); // Don't want to rethrow! ++ Bukkit.getLogger().log(Level.WARNING, "Exception posting ServerExceptionEvent", t); // Don't want to rethrow! + } + } +} diff --git a/patches/server/Add-Alternate-Current-redstone-implementation.patch b/patches/server/Add-Alternate-Current-redstone-implementation.patch index 626b58a963..067e84470e 100644 --- a/patches/server/Add-Alternate-Current-redstone-implementation.patch +++ b/patches/server/Add-Alternate-Current-redstone-implementation.patch @@ -2017,8 +2017,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 public boolean hasEntityMoveEvent = false; // Paper + private final alternate.current.wire.WireHandler wireHandler = new alternate.current.wire.WireHandler(this); // Paper - optimize redstone (Alternate Current) public static Throwable getAddToWorldStackTrace(Entity entity) { - return new Throwable(entity + " Added to world at " + new java.util.Date()); - } + final Throwable thr = new Throwable(entity + " Added to world at " + new java.util.Date()); + io.papermc.paper.util.StacktraceDeobfuscator.INSTANCE.deobfuscateThrowable(thr); @@ -0,0 +0,0 @@ public class ServerLevel extends Level implements WorldGenLevel { // Paper end - rewrite chunk system } diff --git a/patches/server/Deobfuscate-stacktraces-in-log-messages-crash-report.patch b/patches/server/Deobfuscate-stacktraces-in-log-messages-crash-report.patch index 09aa16c7c4..81dd58173f 100644 --- a/patches/server/Deobfuscate-stacktraces-in-log-messages-crash-report.patch +++ b/patches/server/Deobfuscate-stacktraces-in-log-messages-crash-report.patch @@ -475,6 +475,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + final Throwable throwable = new Throwable(reason); + StacktraceDeobfuscator.INSTANCE.deobfuscateThrowable(throwable); + throwable.printStackTrace(); ++ } ++ ++ public static void printStackTrace(Throwable thr) { ++ StacktraceDeobfuscator.INSTANCE.deobfuscateThrowable(thr); ++ thr.printStackTrace(); } } diff --git a/src/main/java/net/minecraft/CrashReport.java b/src/main/java/net/minecraft/CrashReport.java @@ -522,6 +527,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 }); private final PacketFlow receiving; private final Queue queue = Queues.newConcurrentLinkedQueue(); +@@ -0,0 +0,0 @@ public class Connection extends SimpleChannelInboundHandler> { + + } + } +- if (net.minecraft.server.MinecraftServer.getServer().isDebugging()) throwable.printStackTrace(); // Spigot ++ if (net.minecraft.server.MinecraftServer.getServer().isDebugging()) io.papermc.paper.util.TraceUtil.printStackTrace(throwable); // Spigot // Paper + } + + protected void channelRead0(ChannelHandlerContext channelhandlercontext, Packet packet) { diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java @@ -534,6 +548,30 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 paperConfigurations.initializeGlobalConfiguration(); paperConfigurations.initializeWorldDefaultsConfiguration(); org.spigotmc.WatchdogThread.doStart(org.spigotmc.SpigotConfig.timeoutTime, org.spigotmc.SpigotConfig.restartOnCrash); +diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/server/level/ServerLevel.java ++++ b/src/main/java/net/minecraft/server/level/ServerLevel.java +@@ -0,0 +0,0 @@ public class ServerLevel extends Level implements WorldGenLevel { + public final UUID uuid; + public boolean hasPhysicsEvent = true; // Paper + public static Throwable getAddToWorldStackTrace(Entity entity) { +- return new Throwable(entity + " Added to world at " + new java.util.Date()); ++ final Throwable thr = new Throwable(entity + " Added to world at " + new java.util.Date()); ++ io.papermc.paper.util.StacktraceDeobfuscator.INSTANCE.deobfuscateThrowable(thr); ++ return thr; + } + + @Override public LevelChunk getChunkIfLoaded(int x, int z) { // Paper - this was added in world too but keeping here for NMS ABI +@@ -0,0 +0,0 @@ public class ServerLevel extends Level implements WorldGenLevel { + if (entity.isRemoved()) { + // Paper start + if (DEBUG_ENTITIES) { +- new Throwable("Tried to add entity " + entity + " but it was marked as removed already").printStackTrace(); // CraftBukkit ++ io.papermc.paper.util.TraceUtil.dumpTraceForThread("Tried to add entity " + entity + " but it was marked as removed already"); // CraftBukkit + getAddToWorldStackTrace(entity).printStackTrace(); + } + // Paper end diff --git a/src/main/java/net/minecraft/server/network/ServerConnectionListener.java b/src/main/java/net/minecraft/server/network/ServerConnectionListener.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/server/network/ServerConnectionListener.java @@ -551,6 +589,54 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 }); final MinecraftServer server; public volatile boolean running; +diff --git a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java ++++ b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java +@@ -0,0 +0,0 @@ public class ServerLoginPacketListenerImpl implements TickablePacketListener, Se + MutableComponent ichatmutablecomponent = Component.translatable("multiplayer.disconnect.invalid_player_data"); + // Paper start + if (MinecraftServer.getServer().isDebugging()) { +- exception.printStackTrace(); ++ io.papermc.paper.util.TraceUtil.printStackTrace(exception); + } + // Paper end + +diff --git a/src/main/java/net/minecraft/server/players/OldUsersConverter.java b/src/main/java/net/minecraft/server/players/OldUsersConverter.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/server/players/OldUsersConverter.java ++++ b/src/main/java/net/minecraft/server/players/OldUsersConverter.java +@@ -0,0 +0,0 @@ public class OldUsersConverter { + try { + root = NbtIo.readCompressed(new java.io.FileInputStream(file5)); + } catch (Exception exception) { +- exception.printStackTrace(); ++ io.papermc.paper.util.TraceUtil.printStackTrace(exception); // Paper + ServerInternalException.reportInternalException(exception); // Paper + } + +@@ -0,0 +0,0 @@ public class OldUsersConverter { + try { + NbtIo.writeCompressed(root, new java.io.FileOutputStream(file2)); + } catch (Exception exception) { +- exception.printStackTrace(); ++ io.papermc.paper.util.TraceUtil.printStackTrace(exception); // Paper + ServerInternalException.reportInternalException(exception); // Paper + } + } +diff --git a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java ++++ b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java +@@ -0,0 +0,0 @@ public class LevelChunk extends ChunkAccess { + + " (" + getBlockState(blockposition) + ") where there was no entity tile!\n" + + "Chunk coordinates: " + (this.chunkPos.x * 16) + "," + (this.chunkPos.z * 16) + + "\nWorld: " + level.getLevel().dimension().location()); +- e.printStackTrace(); ++ io.papermc.paper.util.TraceUtil.printStackTrace(e); + ServerInternalException.reportInternalException(e); + // Paper end + // CraftBukkit end diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftAsyncScheduler.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftAsyncScheduler.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftAsyncScheduler.java diff --git a/patches/server/EntityMoveEvent.patch b/patches/server/EntityMoveEvent.patch index 8bcfd66dd5..b4c6347d1b 100644 --- a/patches/server/EntityMoveEvent.patch +++ b/patches/server/EntityMoveEvent.patch @@ -26,8 +26,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 public boolean hasPhysicsEvent = true; // Paper + public boolean hasEntityMoveEvent = false; // Paper public static Throwable getAddToWorldStackTrace(Entity entity) { - return new Throwable(entity + " Added to world at " + new java.util.Date()); - } + final Throwable thr = new Throwable(entity + " Added to world at " + new java.util.Date()); + io.papermc.paper.util.StacktraceDeobfuscator.INSTANCE.deobfuscateThrowable(thr); diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/entity/LivingEntity.java diff --git a/patches/server/Fix-Longstanding-Broken-behavior-of-PlayerJoinEvent.patch b/patches/server/Fix-Longstanding-Broken-behavior-of-PlayerJoinEvent.patch index 6d9248a36a..154acb16e5 100644 --- a/patches/server/Fix-Longstanding-Broken-behavior-of-PlayerJoinEvent.patch +++ b/patches/server/Fix-Longstanding-Broken-behavior-of-PlayerJoinEvent.patch @@ -32,7 +32,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 --- a/src/main/java/net/minecraft/server/level/ChunkMap.java +++ b/src/main/java/net/minecraft/server/level/ChunkMap.java @@ -0,0 +0,0 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider - .printStackTrace(); + + ": " + entity + (this.entityMap.containsKey(entity.getId()) ? " ALREADY CONTAINED (This would have crashed your server)" : ""), new Throwable()); return; } + if (entity instanceof ServerPlayer && ((ServerPlayer) entity).supressTrackerForLogin) return; // Delay adding to tracker until after list packets diff --git a/patches/server/MC-Utils.patch b/patches/server/MC-Utils.patch index de4b58f092..c8ba55fee7 100644 --- a/patches/server/MC-Utils.patch +++ b/patches/server/MC-Utils.patch @@ -5292,7 +5292,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + public static void ensureMain(String reason, Runnable run) { + if (!isMainThread()) { + if (reason != null) { -+ new IllegalStateException("Asynchronous " + reason + "!").printStackTrace(); ++ MinecraftServer.LOGGER.warn("Asynchronous " + reason + "!", new IllegalStateException()); + } + getProcessQueue().add(run); + return; @@ -5317,7 +5317,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + public static T ensureMain(String reason, Supplier run) { + if (!isMainThread()) { + if (reason != null) { -+ new IllegalStateException("Asynchronous " + reason + "! Blocking thread until it returns ").printStackTrace(); ++ MinecraftServer.LOGGER.warn("Asynchronous " + reason + "! Blocking thread until it returns ", new IllegalStateException()); + } + Waitable wait = new Waitable() { + @Override @@ -5329,7 +5329,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + try { + return wait.get(); + } catch (InterruptedException | ExecutionException e) { -+ e.printStackTrace(); ++ MinecraftServer.LOGGER.warn("Encountered exception", e); + } + return null; + } diff --git a/patches/server/Prevent-Double-PlayerChunkMap-adds-crashing-server.patch b/patches/server/Prevent-Double-PlayerChunkMap-adds-crashing-server.patch index 640d874e37..374c5b2fd3 100644 --- a/patches/server/Prevent-Double-PlayerChunkMap-adds-crashing-server.patch +++ b/patches/server/Prevent-Double-PlayerChunkMap-adds-crashing-server.patch @@ -16,9 +16,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 org.spigotmc.AsyncCatcher.catchOp("entity track"); // Spigot + // Paper start - ignore and warn about illegal addEntity calls instead of crashing server + if (!entity.valid || entity.level != this.level || this.entityMap.containsKey(entity.getId())) { -+ new Throwable("[ERROR] Illegal PlayerChunkMap::addEntity for world " + this.level.getWorld().getName() -+ + ": " + entity + (this.entityMap.containsKey(entity.getId()) ? " ALREADY CONTAINED (This would have crashed your server)" : "")) -+ .printStackTrace(); ++ LOGGER.error("Illegal ChunkMap::addEntity for world " + this.level.getWorld().getName() ++ + ": " + entity + (this.entityMap.containsKey(entity.getId()) ? " ALREADY CONTAINED (This would have crashed your server)" : ""), new Throwable()); + return; + } + // Paper end