From d0301b414a0bd6247126f9c86833c02349b8c914 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Wed, 10 Jan 2024 18:04:16 +0100 Subject: [PATCH] fix(common-utils): Do not extract TAR directory entries as files This works around [1]. Still keep the `isFile` check to be on the safe side and e.g. skip links. Resolves #8098. [1]: https://issues.apache.org/jira/browse/COMPRESS-657 Signed-off-by: Sebastian Schuberth --- utils/common/src/main/kotlin/ArchiveUtils.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/utils/common/src/main/kotlin/ArchiveUtils.kt b/utils/common/src/main/kotlin/ArchiveUtils.kt index fdbda6b89ebb0..d0816eeca3627 100644 --- a/utils/common/src/main/kotlin/ArchiveUtils.kt +++ b/utils/common/src/main/kotlin/ArchiveUtils.kt @@ -258,7 +258,9 @@ fun InputStream.unpackZip(targetDirectory: File) = fun InputStream.unpackTar(targetDirectory: File, filter: (ArchiveEntry) -> Boolean = { true }) = TarArchiveInputStream(this).unpack( targetDirectory, - { entry -> !(entry as TarArchiveEntry).isFile || File(entry.name).isAbsolute || !filter(entry) }, + { entry -> + (entry as TarArchiveEntry).isDirectory || !entry.isFile || File(entry.name).isAbsolute || !filter(entry) + }, { entry -> (entry as TarArchiveEntry).mode } )