0
0
mirror of https://hub.spigotmc.org/stash/scm/spigot/spigot.git synced 2024-11-21 20:56:14 +00:00
spigot/CraftBukkit-Patches/0053-Safer-JSON-Loading.patch
2024-10-23 02:15:00 +11:00

45 lines
2.3 KiB
Diff

From a6c029e15eb1f1131a8ac4ecbfc9a7b43c00e6f3 Mon Sep 17 00:00:00 2001
From: Suddenly <suddenly@suddenly.coffee>
Date: Tue, 8 Jul 2014 09:44:18 +1000
Subject: [PATCH] Safer JSON Loading
diff --git a/src/main/java/net/minecraft/server/players/JsonList.java b/src/main/java/net/minecraft/server/players/JsonList.java
index f4544fb327..e10fc779bd 100644
--- a/src/main/java/net/minecraft/server/players/JsonList.java
+++ b/src/main/java/net/minecraft/server/players/JsonList.java
@@ -175,6 +175,14 @@ public abstract class JsonList<K, V extends JsonListEntry<K>> {
this.map.put(this.getKeyForUser(jsonlistentry.getUser()), (V) jsonlistentry); // CraftBukkit - decompile error
}
}
+ // Spigot Start
+ } catch ( com.google.gson.JsonParseException | NullPointerException ex )
+ {
+ org.bukkit.Bukkit.getLogger().log( java.util.logging.Level.WARNING, "Unable to read file " + this.file + ", backing it up to {0}.backup and creating new copy.", ex );
+ File backup = new File( this.file + ".backup" );
+ this.file.renameTo( backup );
+ this.file.delete();
+ // Spigot End
} catch (Throwable throwable) {
if (bufferedreader != null) {
try {
diff --git a/src/main/java/net/minecraft/server/players/UserCache.java b/src/main/java/net/minecraft/server/players/UserCache.java
index cc3da591e4..58cc3b5247 100644
--- a/src/main/java/net/minecraft/server/players/UserCache.java
+++ b/src/main/java/net/minecraft/server/players/UserCache.java
@@ -250,6 +250,11 @@ public class UserCache {
}
} catch (FileNotFoundException filenotfoundexception) {
;
+ // Spigot Start
+ } catch (com.google.gson.JsonSyntaxException | NullPointerException ex) {
+ UserCache.LOGGER.warn( "Usercache.json is corrupted or has bad formatting. Deleting it to prevent further issues." );
+ this.file.delete();
+ // Spigot End
} catch (JsonParseException | IOException ioexception) {
UserCache.LOGGER.warn("Failed to load profile cache {}", this.file, ioexception);
}
--
2.47.0