From 3c999ace3aaa950426ceae78fba3fe1e78a38aaa Mon Sep 17 00:00:00 2001 From: marian Date: Sat, 10 Aug 2024 17:53:41 +0200 Subject: [PATCH] improve robustness of archive reader and library metadata reading --- core/pom.xml | 4 ++++ .../v1/reader/archive/ArchiveStoryPackReader.java | 12 ++++++------ pom.xml | 9 +++++++-- .../java/studio/webui/service/LibraryService.java | 7 +++++-- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 058c16cf9..d278cfd39 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -33,6 +33,10 @@ commons-codec commons-codec + + org.apache.commons + commons-compress + com.googlecode.soundlibs vorbisspi diff --git a/core/src/main/java/studio/core/v1/reader/archive/ArchiveStoryPackReader.java b/core/src/main/java/studio/core/v1/reader/archive/ArchiveStoryPackReader.java index 44527ae9a..6e24f73ea 100644 --- a/core/src/main/java/studio/core/v1/reader/archive/ArchiveStoryPackReader.java +++ b/core/src/main/java/studio/core/v1/reader/archive/ArchiveStoryPackReader.java @@ -9,6 +9,8 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; +import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; import org.apache.commons.io.IOUtils; import studio.core.v1.Constants; import studio.core.v1.model.*; @@ -22,14 +24,12 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.util.*; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; public class ArchiveStoryPackReader { public StoryPackMetadata readMetadata(InputStream inputStream) throws IOException { // Zip archive contains a json file and separate assets - ZipInputStream zis = new ZipInputStream(inputStream); + ZipArchiveInputStream zis = new ZipArchiveInputStream(inputStream); // Pack metadata model StoryPackMetadata metadata = new StoryPackMetadata(Constants.PACK_FORMAT_ARCHIVE); @@ -37,7 +37,7 @@ public StoryPackMetadata readMetadata(InputStream inputStream) throws IOExceptio boolean hasStoryJsonEntry = false; - ZipEntry entry; + ZipArchiveEntry entry; while((entry = zis.getNextEntry()) != null) { // Story descriptor file: story.json if (!entry.isDirectory() && entry.getName().equalsIgnoreCase("story.json")) { @@ -81,7 +81,7 @@ else if (!entry.isDirectory() && entry.getName().startsWith("assets/")) { public StoryPack read(InputStream inputStream) throws IOException { // Zip archive contains a json file and separate assets - ZipInputStream zis = new ZipInputStream(inputStream); + ZipArchiveInputStream zis = new ZipArchiveInputStream(inputStream); // Store assets bytes TreeMap assets = new TreeMap<>(); @@ -100,7 +100,7 @@ public StoryPack read(InputStream inputStream) throws IOException { boolean nightModeAvailable = false; - ZipEntry entry; + ZipArchiveEntry entry; while((entry = zis.getNextEntry()) != null) { // Story descriptor file: story.json if (!entry.isDirectory() && entry.getName().equalsIgnoreCase("story.json")) { diff --git a/pom.xml b/pom.xml index b1d0f160a..581b66b54 100644 --- a/pom.xml +++ b/pom.xml @@ -49,12 +49,17 @@ commons-io commons-io - 2.6 + 2.16.1 commons-codec commons-codec - 1.12 + 1.17.1 + + + org.apache.commons + commons-compress + 1.27.0 diff --git a/web-ui/src/main/java/studio/webui/service/LibraryService.java b/web-ui/src/main/java/studio/webui/service/LibraryService.java index e34a24e02..ab955bde6 100644 --- a/web-ui/src/main/java/studio/webui/service/LibraryService.java +++ b/web-ui/src/main/java/studio/webui/service/LibraryService.java @@ -441,8 +441,9 @@ private Optional readPackFile(Path path) { if (meta != null) { return Optional.of(new LibraryPack(path, Files.getLastModifiedTime(path).toMillis() , meta)); } + LOGGER.warn("Failed to read metadata for story pack: " + path.toString()); return Optional.empty(); - } catch (IOException e) { + } catch (Exception e) { LOGGER.error("Failed to read archive-format pack " + path.toString() + " from local library", e); return Optional.empty(); } @@ -456,8 +457,9 @@ private Optional readPackFile(Path path) { meta.setSectorSize(packSectorSize); return Optional.of(new LibraryPack(path, Files.getLastModifiedTime(path).toMillis() , meta)); } + LOGGER.warn("Failed to read metadata for story pack: " + path.toString()); return Optional.empty(); - } catch (IOException e) { + } catch (Exception e) { LOGGER.error("Failed to read raw format pack " + path.toString() + " from local library", e); return Optional.empty(); } @@ -471,6 +473,7 @@ private Optional readPackFile(Path path) { meta.setSectorSize(packSectorSize); return Optional.of(new LibraryPack(path, Files.getLastModifiedTime(path).toMillis() , meta)); } + LOGGER.warn("Failed to read metadata for story pack: " + path.toString()); return Optional.empty(); } catch (Exception e) { LOGGER.error("Failed to read FS format pack " + path.toString() + " from local library", e);