spigot/CraftBukkit-Patches/0074-Safer-JSON-Loading.patch

45 lines
1.9 KiB
Diff
Raw Normal View History

From 6fd55099c14826704d24ad078af42c1daa5ad03d Mon Sep 17 00:00:00 2001
2014-07-08 09:44:30 +10:00
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/JsonList.java b/src/main/java/net/minecraft/server/JsonList.java
2020-01-22 08:00:00 +11:00
index ba96dbae9..734e7ecf6 100644
2014-07-08 09:44:30 +10:00
--- a/src/main/java/net/minecraft/server/JsonList.java
+++ b/src/main/java/net/minecraft/server/JsonList.java
2018-12-26 08:00:00 +11:00
@@ -189,6 +189,14 @@ public class JsonList<K, V extends JsonListEntry<K>> {
2018-07-15 10:00:00 +10:00
}
}
}
2017-05-19 21:00:22 +10:00
+ // Spigot Start
+ } catch ( com.google.gson.JsonParseException ex )
2017-05-19 21:00:22 +10:00
+ {
+ org.bukkit.Bukkit.getLogger().log( java.util.logging.Level.WARNING, "Unable to read file " + this.c + ", backing it up to {0}.backup and creating new copy.", ex );
2017-05-19 21:00:22 +10:00
+ File backup = new File( this.c + ".backup" );
+ this.c.renameTo( backup );
+ this.c.delete();
+ // Spigot End
} finally {
IOUtils.closeQuietly(bufferedreader);
}
2014-07-08 09:44:30 +10:00
diff --git a/src/main/java/net/minecraft/server/UserCache.java b/src/main/java/net/minecraft/server/UserCache.java
2020-01-22 08:00:00 +11:00
index a847f74d9..65659996c 100644
2014-07-08 09:44:30 +10:00
--- a/src/main/java/net/minecraft/server/UserCache.java
+++ b/src/main/java/net/minecraft/server/UserCache.java
2018-12-26 08:00:00 +11:00
@@ -207,6 +207,11 @@ public class UserCache {
2014-07-08 09:44:30 +10:00
}
2015-05-09 21:23:26 +01:00
} catch (FileNotFoundException filenotfoundexception) {
;
+ // Spigot Start
+ } catch (com.google.gson.JsonSyntaxException ex) {
2019-04-25 12:00:00 +10:00
+ JsonList.LOGGER.warn( "Usercache.json is corrupted or has bad formatting. Deleting it to prevent further issues." );
2016-03-01 08:33:06 +11:00
+ this.h.delete();
2015-05-09 21:23:26 +01:00
+ // Spigot End
} catch (JsonParseException jsonparseexception) {
;
} finally {
2014-07-08 09:44:30 +10:00
--
2.25.1
2014-07-08 09:44:30 +10:00