Skip to content

Commit

Permalink
ArchiveUtils: Also do not follow symbolic links to directories
Browse files Browse the repository at this point in the history
The fix in 3342e50 was incomplete in that only symbolic links to files
were not followed. Extend this to symbolic links to directories.

Resolves #5376, again.

Signed-off-by: Sebastian Schuberth <sebastian.schuberth@bosch.io>
  • Loading branch information
sschuberth committed May 25, 2022
1 parent 31b648c commit 42c98ed
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion utils/common/src/main/kotlin/ArchiveUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ fun File.packZip(
output.setLevel(Deflater.BEST_COMPRESSION)

walkTopDown().onEnter {
directoryFilter(it)
Files.isDirectory(it.toPath(), LinkOption.NOFOLLOW_LINKS) && directoryFilter(it)
}.filter {
Files.isRegularFile(it.toPath(), LinkOption.NOFOLLOW_LINKS) && fileFilter(it) && it != targetFile
}.forEach { file ->
Expand Down
18 changes: 18 additions & 0 deletions utils/common/src/test/kotlin/ArchiveUtilsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import io.kotest.matchers.string.shouldContain

import java.io.File
import java.io.IOException
import java.nio.file.Files

import org.apache.commons.compress.archivers.ArchiveEntry

Expand Down Expand Up @@ -413,6 +414,23 @@ class ArchiveUtilsTest : WordSpec() {
exception.message shouldContain noArchive.toString()
}
}

"packZip" should {
"not follow symbolic links".config(enabled = Os.isLinux) {
val inputDir = createTestTempDir()
val parentDir = inputDir.resolve("parent").apply { safeMkdirs() }
val readmeFile = parentDir.resolve("readme.txt").apply { writeText("Hello World!") }
Files.createSymbolicLink(parentDir.resolve("loop-link").toPath(), parentDir.toPath())
Files.createSymbolicLink(parentDir.resolve("readme-link.txt").toPath(), readmeFile.toPath())

val zipFile = inputDir.packZip(outputDir.resolve("archive.zip")) {
it shouldBe readmeFile
true
}

zipFile shouldBe aFile()
}
}
}
}

Expand Down

0 comments on commit 42c98ed

Please sign in to comment.