Skip to content

Commit 750f5d6

Browse files
committed
Disallow file system root zipping.
The StudentFileAwareZipper includes the provided root directory in the zip archive as a parent directory. File system roots aren't named directories, so they cannot be added as such.
1 parent 0c597af commit 750f5d6

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

tmc-langs-framework/src/main/java/fi/helsinki/cs/tmc/langs/io/zip/StudentFileAwareZipper.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,16 @@ public byte[] zip(Path rootDirectory) throws IOException {
4040
log.debug("Starting to zip {}", rootDirectory);
4141

4242
if (!Files.exists(rootDirectory)) {
43-
log.error("Attempted to zip nonexistent directory {}", rootDirectory);
43+
log.error("Attempted to zip nonexistent directory \"{}\"", rootDirectory);
4444
throw new FileNotFoundException("Attempted to zip nonexistent directory");
4545
}
4646

47+
if (rootDirectory.toAbsolutePath().getNameCount() == 0) {
48+
// getNameCount returns 0 if the path only represents a root component
49+
log.error("Attempted to zip a root \"{}\"", rootDirectory);
50+
throw new IllegalArgumentException("Filesystem root zipping is not supported");
51+
}
52+
4753
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
4854
try (ZipArchiveOutputStream zipStream = new ZipArchiveOutputStream(buffer)) {
4955
zipRecursively(rootDirectory, zipStream, rootDirectory);

0 commit comments

Comments
 (0)