summaryrefslogtreecommitdiffstats
path: root/application-model
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2024-02-29 09:35:15 +0100
committerMartin Polden <mpolden@mpolden.no>2024-02-29 09:35:15 +0100
commit29d14cc29dc8c354825a0ea5ad566eb8bc658f6c (patch)
tree3d03e8b88e959f457fcb5de505d63ec93fdee430 /application-model
parent8dfdfa1c4962442123ad10df75f783f7c50ef673 (diff)
Improve exception messages for invalid archive
Diffstat (limited to 'application-model')
-rw-r--r--application-model/src/main/java/com/yahoo/vespa/archive/ArchiveStreamReader.java12
1 files changed, 8 insertions, 4 deletions
diff --git a/application-model/src/main/java/com/yahoo/vespa/archive/ArchiveStreamReader.java b/application-model/src/main/java/com/yahoo/vespa/archive/ArchiveStreamReader.java
index b7ad4ac6279..a7106805a75 100644
--- a/application-model/src/main/java/com/yahoo/vespa/archive/ArchiveStreamReader.java
+++ b/application-model/src/main/java/com/yahoo/vespa/archive/ArchiveStreamReader.java
@@ -55,10 +55,10 @@ public class ArchiveStreamReader implements AutoCloseable {
try {
while ((entry = archiveInputStream.getNextEntry()) != null) {
Path path = Path.fromString(requireNormalized(entry.getName(), options.allowDotSegment));
- if (isSymlink(entry)) throw new IllegalArgumentException("Archive entry " + path + " is a symbolic link, which is unsupported");
+ if (isSymlink(entry)) throw new IllegalArgumentException(archiveType() + " entry " + path + " is a symbolic link, which is unsupported");
if (entry.isDirectory()) continue;
if (!options.pathPredicate.test(path.toString())) continue;
- if (++entriesRead > options.maxEntries) throw new IllegalArgumentException("Attempted to read more entries than entry limit of " + options.maxEntries);
+ if (++entriesRead > options.maxEntries) throw new IllegalArgumentException(archiveType() + " contains more files than the limit of " + options.maxEntries);
long size = 0;
byte[] buffer = new byte[2048];
@@ -66,9 +66,9 @@ public class ArchiveStreamReader implements AutoCloseable {
while ((read = archiveInputStream.read(buffer)) != -1) {
totalRead += read;
size += read;
- if (totalRead > options.maxSize) throw new IllegalArgumentException("Total size of archive exceeds size limit of " + options.maxSize + " bytes");
+ if (totalRead > options.maxSize) throw new IllegalArgumentException("Total size of " + archiveType() + " exceeds size limit of " + options.maxSize + " bytes");
if (read > options.maxEntrySize) {
- if (!options.truncateEntry) throw new IllegalArgumentException("Size of entry " + path + " exceeded entry size limit of " + options.maxEntrySize + " bytes");
+ if (!options.truncateEntry) throw new IllegalArgumentException("Size of " + archiveType() + " entry " + path + " exceeded entry size limit of " + options.maxEntrySize + " bytes");
} else {
outputStream.write(buffer, 0, read);
}
@@ -86,6 +86,10 @@ public class ArchiveStreamReader implements AutoCloseable {
Exceptions.uncheck(archiveInputStream::close);
}
+ private String archiveType() {
+ return archiveInputStream instanceof TarArchiveInputStream ? "TAR" : "ZIP";
+ }
+
/** Information about a file extracted from a compressed archive */
public static class ArchiveFile {