diff options
author | Martin Polden <mpolden@mpolden.no> | 2022-04-05 11:04:04 +0200 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2022-04-05 14:07:58 +0200 |
commit | b1084cec06681d05a6f822d32acf0390691cdc50 (patch) | |
tree | aa2aea069d91ca3e73b2b23030aba3cef7fab723 /vespajlib | |
parent | 49e7a8c8cee5e93317593bbd1253f555327e7482 (diff) |
Make max application package size configurable
Diffstat (limited to 'vespajlib')
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/compress/ArchiveStreamReader.java | 20 | ||||
-rw-r--r-- | vespajlib/src/test/java/com/yahoo/compress/ArchiveStreamReaderTest.java | 8 |
2 files changed, 14 insertions, 14 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/compress/ArchiveStreamReader.java b/vespajlib/src/main/java/com/yahoo/compress/ArchiveStreamReader.java index 748db06c70d..30dbd946155 100644 --- a/vespajlib/src/main/java/com/yahoo/compress/ArchiveStreamReader.java +++ b/vespajlib/src/main/java/com/yahoo/compress/ArchiveStreamReader.java @@ -65,8 +65,8 @@ public class ArchiveStreamReader implements AutoCloseable { while ((read = archiveInputStream.read(buffer)) != -1) { totalRead += read; size += read; - if (totalRead > options.sizeLimit) throw new IllegalArgumentException("Total size of archive exceeds size limit"); - if (read > options.entrySizeLimit) { + if (totalRead > options.maxSize) throw new IllegalArgumentException("Total size of archive exceeds size limit"); + if (read > options.maxEntrySize) { if (!options.truncateEntry) throw new IllegalArgumentException("Size of entry " + path + " exceeded entry size limit"); } else { outputStream.write(buffer, 0, read); @@ -156,8 +156,8 @@ public class ArchiveStreamReader implements AutoCloseable { /** Options for reading entries of an archive */ public static class Options { - private long sizeLimit = 8 * (long) Math.pow(1024, 3); // 8 GB - private long entrySizeLimit = Long.MAX_VALUE; + private long maxSize = 8 * (long) Math.pow(1024, 3); // 8 GB + private long maxEntrySize = Long.MAX_VALUE; private boolean truncateEntry = false; private boolean allowDotSegment = false; private Predicate<String> pathPredicate = (path) -> true; @@ -169,15 +169,15 @@ public class ArchiveStreamReader implements AutoCloseable { return new Options(); } - /** Set the total size limit when decompressing entries. Default is 8 GB */ - public Options sizeLimit(long limit) { - this.sizeLimit = limit; + /** Set the maximum total size of decompressed entries. Default is 8 GB */ + public Options maxSize(long size) { + this.maxSize = size; return this; } - /** Set the size limit of a decompressed entry. Default is no limit */ - public Options entrySizeLimit(long limit) { - this.entrySizeLimit = limit; + /** Set the maximum size a decompressed entry. Default is no limit */ + public Options maxEntrySize(long size) { + this.maxEntrySize = size; return this; } diff --git a/vespajlib/src/test/java/com/yahoo/compress/ArchiveStreamReaderTest.java b/vespajlib/src/test/java/com/yahoo/compress/ArchiveStreamReaderTest.java index 847ab4124d3..a288b9f0c55 100644 --- a/vespajlib/src/test/java/com/yahoo/compress/ArchiveStreamReaderTest.java +++ b/vespajlib/src/test/java/com/yahoo/compress/ArchiveStreamReaderTest.java @@ -39,7 +39,7 @@ class ArchiveStreamReaderTest { @Test void entry_size_limit() { Map<String, String> entries = Map.of("foo.xml", "foobar"); - Options options = Options.standard().pathPredicate("foo.xml"::equals).entrySizeLimit(1); + Options options = Options.standard().pathPredicate("foo.xml"::equals).maxEntrySize(1); try { readAll(zip(entries), options); fail("Expected exception"); @@ -48,7 +48,7 @@ class ArchiveStreamReaderTest { entries = Map.of("foo.xml", "foobar", "foo.jar", "0".repeat(100) // File not extracted and thus not subject to size limit ); - Map<String, String> extracted = readAll(zip(entries), options.entrySizeLimit(10)); + Map<String, String> extracted = readAll(zip(entries), options.maxEntrySize(10)); assertEquals(Map.of("foo.xml", "foobar"), extracted); } @@ -56,7 +56,7 @@ class ArchiveStreamReaderTest { void size_limit() { Map<String, String> entries = Map.of("foo.xml", "foo", "bar.xml", "bar"); try { - readAll(zip(entries), Options.standard().sizeLimit(4)); + readAll(zip(entries), Options.standard().maxSize(4)); fail("Expected exception"); } catch (IllegalArgumentException ignored) {} } @@ -75,7 +75,7 @@ class ArchiveStreamReaderTest { "services.xml", false ); - Options options = Options.standard().entrySizeLimit(1024); + Options options = Options.standard().maxEntrySize(1024); tests.forEach((name, expectException) -> { try { readAll(zip(Map.of(name, "foo")), options.pathPredicate(name::equals)); |