From 060b304a4f2a86dae79e6648cdc86ac45290155a Mon Sep 17 00:00:00 2001 From: Davy Landman Date: Wed, 3 Apr 2024 10:56:24 +0200 Subject: [PATCH] Removed XZ compression feature of serialized IValues Fixes #252 --- pom.xml | 5 ----- .../usethesource/vallang/io/binary/stream/Compressor.java | 7 ++----- .../io/usethesource/vallang/io/binary/stream/Header.java | 1 + .../vallang/io/binary/stream/IValueInputStream.java | 4 ++++ .../vallang/io/binary/stream/IValueOutputStream.java | 2 +- 5 files changed, 8 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index 1a71daf2c..4b5eee464 100644 --- a/pom.xml +++ b/pom.xml @@ -153,11 +153,6 @@ capsule 0.7.1 - - org.tukaani - xz - 1.9 - com.github.luben zstd-jni diff --git a/src/main/java/io/usethesource/vallang/io/binary/stream/Compressor.java b/src/main/java/io/usethesource/vallang/io/binary/stream/Compressor.java index 9d65c7261..6064136f1 100644 --- a/src/main/java/io/usethesource/vallang/io/binary/stream/Compressor.java +++ b/src/main/java/io/usethesource/vallang/io/binary/stream/Compressor.java @@ -27,9 +27,6 @@ import java.io.OutputStream; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; -import org.tukaani.xz.LZMA2Options; -import org.tukaani.xz.XZInputStream; -import org.tukaani.xz.XZOutputStream; import com.github.luben.zstd.ZstdInputStream; import com.github.luben.zstd.ZstdOutputStream; import com.github.luben.zstd.util.Native; @@ -61,7 +58,7 @@ public void setLevel(int level) { return result; } case Header.Compression.XZ: { - return new XZOutputStream(rawStream, new LZMA2Options(level)); + throw new IOException("XZ compression is not supported anymore, please use an older version of rascal/vallang to open the file and store it with a different level of compression"); } case Header.Compression.ZSTD: { return new ZstdOutputStream(rawStream, level); @@ -78,7 +75,7 @@ public static InputStream wrapStream(InputStream raw, int algorithm) throws IOEx case Header.Compression.GZIP: return new GZIPInputStream(raw); case Header.Compression.XZ: - return new XZInputStream(raw); + throw new IOException("XZ compression is not supported anymore, please use an older version of rascal/vallang to open the file and store it with a different level of compression"); case Header.Compression.ZSTD: if (Compressor.zstdAvailable()) { if (raw instanceof ByteBufferInputStream && ((ByteBufferInputStream)raw).getByteBuffer().isDirect()) { diff --git a/src/main/java/io/usethesource/vallang/io/binary/stream/Header.java b/src/main/java/io/usethesource/vallang/io/binary/stream/Header.java index 878d44da6..6e9f58ee2 100644 --- a/src/main/java/io/usethesource/vallang/io/binary/stream/Header.java +++ b/src/main/java/io/usethesource/vallang/io/binary/stream/Header.java @@ -17,6 +17,7 @@ public static final class Compression { public static final byte NONE = 0; public static final byte GZIP = 1; + /** Not used anymore, it was never used, and we're cutting down on dependencies */ public static final byte XZ = 2; public static final byte ZSTD = 3; } diff --git a/src/main/java/io/usethesource/vallang/io/binary/stream/IValueInputStream.java b/src/main/java/io/usethesource/vallang/io/binary/stream/IValueInputStream.java index 86aabf034..4abac8f0c 100644 --- a/src/main/java/io/usethesource/vallang/io/binary/stream/IValueInputStream.java +++ b/src/main/java/io/usethesource/vallang/io/binary/stream/IValueInputStream.java @@ -16,6 +16,7 @@ import java.io.IOException; import java.io.InputStream; import java.nio.channels.FileChannel; +import java.util.Arrays; import java.util.function.Supplier; import org.checkerframework.checker.nullness.qual.Nullable; @@ -49,6 +50,9 @@ public IValueInputStream(InputStream in, IValueFactory vf, Supplier t while (read < currentHeader.length) { read += in.read(currentHeader, read, currentHeader.length - read); } + if (!Arrays.equals(currentHeader, Header.MAIN)) { + throw new IOException("Incorrect file header, are you sure this is a valid file containing a serialized value?"); + } int compression = in.read(); in = Compressor.wrapStream(in, compression); diff --git a/src/main/java/io/usethesource/vallang/io/binary/stream/IValueOutputStream.java b/src/main/java/io/usethesource/vallang/io/binary/stream/IValueOutputStream.java index 7a68603a0..0d91f55ed 100644 --- a/src/main/java/io/usethesource/vallang/io/binary/stream/IValueOutputStream.java +++ b/src/main/java/io/usethesource/vallang/io/binary/stream/IValueOutputStream.java @@ -55,7 +55,7 @@ public enum CompressionRate { Light(Header.Compression.ZSTD, 1), Normal(Header.Compression.ZSTD, 5), Strong(Header.Compression.ZSTD, 13), - Extreme(Header.Compression.XZ, 6), + Extreme(Header.Compression.ZSTD, 19), XML(Compression.NONE, 0) ;