Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-03 01:50:07 +01:00
Harden JsonFileSessionStore against nulls/Gson oddities
Dieser Commit ist enthalten in:
Ursprung
982caaffab
Commit
fa25ad22cd
@ -88,7 +88,15 @@ public class JsonFileSessionStore implements SessionStore {
|
|||||||
try (Closer closer = Closer.create()) {
|
try (Closer closer = Closer.create()) {
|
||||||
FileReader fr = closer.register(new FileReader(file));
|
FileReader fr = closer.register(new FileReader(file));
|
||||||
BufferedReader br = closer.register(new BufferedReader(fr));
|
BufferedReader br = closer.register(new BufferedReader(fr));
|
||||||
return gson.fromJson(br, LocalSession.class);
|
LocalSession session = gson.fromJson(br, LocalSession.class);
|
||||||
|
if (session == null) {
|
||||||
|
log.warn("Loaded a null session from {}, creating new session", file);
|
||||||
|
if (!file.delete()) {
|
||||||
|
log.warn("Failed to delete corrupted session {}", file);
|
||||||
|
}
|
||||||
|
session = new LocalSession();
|
||||||
|
}
|
||||||
|
return session;
|
||||||
} catch (JsonParseException e) {
|
} catch (JsonParseException e) {
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
@ -98,6 +106,7 @@ public class JsonFileSessionStore implements SessionStore {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save(UUID id, LocalSession session) throws IOException {
|
public void save(UUID id, LocalSession session) throws IOException {
|
||||||
|
checkNotNull(session);
|
||||||
File finalFile = getPath(id);
|
File finalFile = getPath(id);
|
||||||
File tempFile = new File(finalFile.getParentFile(), finalFile.getName() + ".tmp");
|
File tempFile = new File(finalFile.getParentFile(), finalFile.getName() + ".tmp");
|
||||||
|
|
||||||
@ -115,6 +124,10 @@ public class JsonFileSessionStore implements SessionStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tempFile.length() == 0) {
|
||||||
|
throw new IllegalStateException("Gson wrote zero bytes");
|
||||||
|
}
|
||||||
|
|
||||||
if (!tempFile.renameTo(finalFile)) {
|
if (!tempFile.renameTo(finalFile)) {
|
||||||
log.warn("Failed to rename temporary session file to " + finalFile.getPath());
|
log.warn("Failed to rename temporary session file to " + finalFile.getPath());
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren