This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git
The following commit(s) were added to refs/heads/master by this push: new 45023ddcc [COMPRESS-655] Fix TAR directory entries being misinterpreted as files (#460) 45023ddcc is described below commit 45023ddcc43e13804dff799ae96f2acce14ce3cd Author: Sebastian Schuberth <sschube...@users.noreply.github.com> AuthorDate: Thu Jan 11 16:26:24 2024 +0100 [COMPRESS-655] Fix TAR directory entries being misinterpreted as files (#460) * Add a failing test for COMPRESS-657 * [COMPRESS-655] Fix TAR directory entries being misinterpreted as files Do not treat directory names without a trailing slash automatically as files. --- .../compress/archivers/tar/TarArchiveEntry.java | 2 +- .../commons/compress/archivers/tar/TarFileTest.java | 13 +++++++++++++ src/test/resources/COMPRESS-657/README.md | 5 +++++ src/test/resources/COMPRESS-657/orjson-3.7.8.tar | Bin 0 -> 1904128 bytes 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java index 420537420..35f49d08a 100644 --- a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java +++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java @@ -1241,7 +1241,7 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants, EntryStreamO if (linkFlag == LF_OLDNORM || linkFlag == LF_NORMAL) { return true; } - return !getName().endsWith("/"); + return linkFlag != LF_DIR && !getName().endsWith("/"); } /** diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarFileTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarFileTest.java index 2677fe9df..f66ee180e 100644 --- a/src/test/java/org/apache/commons/compress/archivers/tar/TarFileTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarFileTest.java @@ -17,6 +17,7 @@ package org.apache.commons.compress.archivers.tar; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; @@ -111,6 +112,18 @@ public class TarFileTest extends AbstractTest { } } + @Test + public void testCompress657() throws IOException { + try (TarFile tarFile = new TarFile(getPath("COMPRESS-657/orjson-3.7.8.tar"))) { + for (final TarArchiveEntry entry : tarFile.getEntries()) { + if (entry.isDirectory()) { + // An entry cannot be a directory and a "normal file" at the same time. + assertFalse(entry.isFile(), "Entry '" + entry.getName() + "' is both a directory and a file"); + } + } + } + } + @Test public void testDatePriorToEpochInGNUFormat() throws Exception { datePriorToEpoch("preepoch-star.tar"); diff --git a/src/test/resources/COMPRESS-657/README.md b/src/test/resources/COMPRESS-657/README.md new file mode 100644 index 000000000..784b1e08f --- /dev/null +++ b/src/test/resources/COMPRESS-657/README.md @@ -0,0 +1,5 @@ +The `orjson-3.7.8.tar` test resource was originally downloaded from [1] and piped through `zcat` to turn it into a +plain TAR as the GZ compression is not related to the bug. The *orjson* project is dual-licensed under Apache-2.0 or MIT, see [2]. + +[1]: https://files.pythonhosted.org/packages/ac/4a/43daa65b7ed984612267983039a58703c48ccbc62561abb43ec7bc8b0663/orjson-3.7.8.tar.gz +[2]: https://github.com/ijl/orjson/issues/448 diff --git a/src/test/resources/COMPRESS-657/orjson-3.7.8.tar b/src/test/resources/COMPRESS-657/orjson-3.7.8.tar new file mode 100644 index 000000000..04a418f1f Binary files /dev/null and b/src/test/resources/COMPRESS-657/orjson-3.7.8.tar differ