[commons-compress] branch master updated: Update my(Peter Lee) personal information in pom
This is an automated email from the ASF dual-hosted git repository. peterlee 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 aa5ea20 Update my(Peter Lee) personal information in pom aa5ea20 is described below commit aa5ea20514557ba474cd834c87e7ab6385eaa119 Author: Lee AuthorDate: Mon Mar 16 10:07:46 2020 +0800 Update my(Peter Lee) personal information in pom update my personal information in pom --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index bc61f52..ea245bd 100644 --- a/pom.xml +++ b/pom.xml @@ -221,9 +221,9 @@ Brotli, Zstandard and ar, cpio, jar, tar, zip, dump, 7z, arj. chtompki at apache.org - Peter Alfred lee - Peter Lee - peteralfredlee at gmail.com + Peter Alfred Lee + peterlee + peterlee at apache.org
[commons-compress] branch master updated: COMPRESS-504 allow setting of compression level in ParallelScatterZipCreator
This is an automated email from the ASF dual-hosted git repository. peterlee 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 7457bbb COMPRESS-504 allow setting of compression level in ParallelScatterZipCreator 7457bbb is described below commit 7457bbbdf76e6a617cdfe2f9314aea540be8db3c Author: PeterAlfredLee AuthorDate: Mon Mar 16 19:41:20 2020 +0800 COMPRESS-504 allow setting of compression level in ParallelScatterZipCreator Allow setting of compression level in ParallelScatterZipCreator, and add some testcases for ParallelScatterZipCreator --- .../archivers/zip/ParallelScatterZipCreator.java | 25 ++- .../zip/ParallelScatterZipCreatorTest.java | 171 - 2 files changed, 193 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreator.java b/src/main/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreator.java index dfa8524..7cd4c23 100644 --- a/src/main/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreator.java +++ b/src/main/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreator.java @@ -59,6 +59,7 @@ public class ParallelScatterZipCreator { private final long startedAt = System.currentTimeMillis(); private long compressionDoneAt = 0; private long scatterDoneAt; +private final int compressionLevel; private static class DefaultBackingStoreSupplier implements ScatterGatherBackingStoreSupplier { final AtomicInteger storeNum = new AtomicInteger(0); @@ -74,7 +75,7 @@ public class ParallelScatterZipCreator { throws IOException { final ScatterGatherBackingStore bs = scatterGatherBackingStoreSupplier.get(); // lifecycle is bound to the ScatterZipOutputStream returned -final StreamCompressor sc = StreamCompressor.create(Deflater.DEFAULT_COMPRESSION, bs); //NOSONAR +final StreamCompressor sc = StreamCompressor.create(compressionLevel, bs); //NOSONAR return new ScatterZipOutputStream(bs, sc); } @@ -118,8 +119,30 @@ public class ParallelScatterZipCreator { */ public ParallelScatterZipCreator(final ExecutorService executorService, final ScatterGatherBackingStoreSupplier backingStoreSupplier) { +this(executorService, backingStoreSupplier, Deflater.DEFAULT_COMPRESSION); +} + +/** + * Create a ParallelScatterZipCreator + * + * @param executorService The executorService to use. For technical reasons, this will be shut down + * by this class. + * @param backingStoreSupplier The supplier of backing store which shall be used + * @param compressionLevel The compression level used in compression, this value should be + * -1(default level) or between 0~9. + * @throws IllegalArgumentException if the compression level is illegal + */ +public ParallelScatterZipCreator(final ExecutorService executorService, + final ScatterGatherBackingStoreSupplier backingStoreSupplier, + final int compressionLevel) throws IllegalArgumentException { +if ((compressionLevel < Deflater.NO_COMPRESSION || compressionLevel > Deflater.BEST_COMPRESSION) +&& compressionLevel != Deflater.DEFAULT_COMPRESSION) { +throw new IllegalArgumentException("Compression level is expected between -1~9"); +} + this.backingStoreSupplier = backingStoreSupplier; es = executorService; +this.compressionLevel = compressionLevel; } /** diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreatorTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreatorTest.java index f2417a9..3ba 100644 --- a/src/test/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreatorTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreatorTest.java @@ -27,6 +27,8 @@ import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.Enumeration; @@ -35,14 +37,21 @@ import java.util.Map; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.zip.Deflater; import java.util.zip.ZipEntry; +import static org.apache.commons.compress.AbstractTestCase.getFile; import static org.apache.commons.compress.AbstractTestCase.tryHardToDelete; -import static org.junit.
[commons-compress] branch master updated: Add @since for ParallelScatterZipCreator
This is an automated email from the ASF dual-hosted git repository. peterlee 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 5401f24 Add @since for ParallelScatterZipCreator 5401f24 is described below commit 5401f24e2f88265378e59b13cf2a0bc3d8310d40 Author: PeterAlfredLee AuthorDate: Tue Mar 17 10:49:27 2020 +0800 Add @since for ParallelScatterZipCreator Add @since for newly added constructor of ParallelScatterZipCreator --- .../apache/commons/compress/archivers/zip/ParallelScatterZipCreator.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreator.java b/src/main/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreator.java index 7cd4c23..3a70f4e 100644 --- a/src/main/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreator.java +++ b/src/main/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreator.java @@ -131,6 +131,7 @@ public class ParallelScatterZipCreator { * @param compressionLevel The compression level used in compression, this value should be * -1(default level) or between 0~9. * @throws IllegalArgumentException if the compression level is illegal + * @since 1.21 */ public ParallelScatterZipCreator(final ExecutorService executorService, final ScatterGatherBackingStoreSupplier backingStoreSupplier,
[commons-compress] branch master updated: COMPRESS-505 : multiple read of same 7z entry fix
This is an automated email from the ASF dual-hosted git repository. peterlee 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 ccf4f3d COMPRESS-505 : multiple read of same 7z entry fix new 9ea37ac Merge pull request #95 from PeterAlfredLee/COMPRESS-505 ccf4f3d is described below commit ccf4f3d856f4ec7f62644bf0a8e0ad6bc155b1f9 Author: Lee AuthorDate: Wed Mar 4 19:58:33 2020 +0800 COMPRESS-505 : multiple read of same 7z entry fix There are exceptions when reading multiple times of same 7z entry. There are also some exceptions when using getNextEntry and getInputStream at the same time. This is the fix for them. --- .../compress/archivers/sevenz/SevenZFile.java | 178 +++-- .../utils/ChecksumVerifyingInputStream.java| 4 + .../compress/archivers/sevenz/SevenZFileTest.java | 122 +- 3 files changed, 255 insertions(+), 49 deletions(-) diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java index 713211a..6d6d085 100644 --- a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java +++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java @@ -405,7 +405,7 @@ public class SevenZFile implements Closeable { if (entry.getName() == null && options.getUseDefaultNameForUnnamedEntries()) { entry.setName(getDefaultName()); } -buildDecodingStream(currentEntryIndex); +buildDecodingStream(currentEntryIndex, false); uncompressedBytesReadFromCurrentEntry = compressedBytesReadFromCurrentEntry = 0; return entry; } @@ -1148,7 +1148,19 @@ public class SevenZFile implements Closeable { archive.streamMap = streamMap; } -private void buildDecodingStream(int entryIndex) throws IOException { +/** + * Build the decoding stream for the entry to be read. + * This method may be called from a random access(getInputStream) or + * sequential access(getNextEntry). + * If this method is called from a random access, some entries may + * need to be skipped(we put them to the deferredBlockStreams and + * skip them when actually needed to improve the performance) + * + * @param entryIndex the index of the entry to be read + * @param isRandomAccess is this called in a random access + * @throws IOException if there are exceptions when reading the file + */ +private void buildDecodingStream(int entryIndex, boolean isRandomAccess) throws IOException { if (archive.streamMap == null) { throw new IOException("Archive doesn't contain stream information to read entries"); } @@ -1161,10 +1173,6 @@ public class SevenZFile implements Closeable { } final SevenZArchiveEntry file = archive.files[entryIndex]; boolean isInSameFolder = false; -final Folder folder = archive.folders[folderIndex]; -final int firstPackStreamIndex = archive.streamMap.folderFirstPackStreamIndex[folderIndex]; -final long folderOffset = SIGNATURE_HEADER_SIZE + archive.packPos + -archive.streamMap.packStreamOffsets[firstPackStreamIndex]; if (currentFolderIndex == folderIndex) { // (COMPRESS-320). // The current entry is within the same (potentially opened) folder. The @@ -1177,54 +1185,27 @@ public class SevenZFile implements Closeable { // if this is called in a random access, then the content methods of previous entry may be null // the content methods should be set to methods of the first entry as it must not be null, // and the content methods would only be set if the content methods was not set -if(currentEntryIndex != entryIndex && file.getContentMethods() == null) { +if(isRandomAccess && file.getContentMethods() == null) { int folderFirstFileIndex = archive.streamMap.folderFirstFileIndex[folderIndex]; SevenZArchiveEntry folderFirstFile = archive.files[folderFirstFileIndex]; file.setContentMethods(folderFirstFile.getContentMethods()); } isInSameFolder = true; } else { -// We're opening a new folder. Discard any queued streams/ folder stream. currentFolderIndex = folderIndex; -deferredBlockStreams.clear(); -if (currentFolderInputStream != null) { -currentFolderInputStream.close(); -currentFolderInputStream = null; -} - -currentFolderInputStream = buildDecoderStack(folder, folderOffset, firstPackStreamIndex, file); +// We're
[commons-compress] branch master updated: minor cleanups for COMPRESS-505
This is an automated email from the ASF dual-hosted git repository. peterlee 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 aeb809c minor cleanups for COMPRESS-505 aeb809c is described below commit aeb809c787dbf2c25dec76a92ac823b338cf721d Author: PeterAlfredLee AuthorDate: Tue Mar 24 15:51:49 2020 +0800 minor cleanups for COMPRESS-505 minor cleanups --- .../compress/archivers/sevenz/SevenZFile.java | 21 + 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java index 6d6d085..2a1d7f9 100644 --- a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java +++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java @@ -1197,9 +1197,13 @@ public class SevenZFile implements Closeable { reopenFolderInputStream(folderIndex, file); } -boolean hasEntriesBeenSkipped = skipEntriesWhenNeeded(entryIndex, isRandomAccess, isInSameFolder, folderIndex); +boolean haveSkippedEntries = false; +if (isRandomAccess) { +// entries will only need to be skipped if it's a random access +haveSkippedEntries = skipEntriesWhenNeeded(entryIndex, isInSameFolder, folderIndex); +} -if (isRandomAccess && currentEntryIndex == entryIndex && !hasEntriesBeenSkipped) { +if (isRandomAccess && currentEntryIndex == entryIndex && !haveSkippedEntries) { // we don't need to add another entry to the deferredBlockStreams when : // 1. If this method is called in a random access and the entry index // to be read equals to the current entry index, the input stream @@ -1254,22 +1258,15 @@ public class SevenZFile implements Closeable { * skip all the entries before the current entries * * @param entryIndex the entry to be read - * @param isRandomAccess is this a random access * @param isInSameFolder are the entry to be read and the current entry in the same folder * @param folderIndexthe index of the folder which contains the entry * @return true if there are entries actually skipped * @throws IOException there are exceptions when skipping entries * @since 1.21 */ -private boolean skipEntriesWhenNeeded(int entryIndex, boolean isRandomAccess, - boolean isInSameFolder, int folderIndex) throws IOException { -// entries will only need to be skipped if it's a random access -if (!isRandomAccess) { -return false; -} - +private boolean skipEntriesWhenNeeded(int entryIndex, boolean isInSameFolder, int folderIndex) throws IOException { final SevenZArchiveEntry file = archive.files[entryIndex]; -boolean isNeedToSkipEntries; +final boolean isNeedToSkipEntries; boolean hasCurrentEntryBeenRead = false; if (currentEntryIndex != entryIndex) { // this means there are some entries to be skipped(currentEntryIndex < entryIndex) @@ -1320,7 +1317,7 @@ public class SevenZFile implements Closeable { // set the content methods as well, it equals to file.getContentMethods() because they are in same folder fileToSkip.setContentMethods(file.getContentMethods()); } -return isNeedToSkipEntries; +return true; } private InputStream buildDecoderStack(final Folder folder, final long folderOffset,
[commons-compress] branch master updated: update changes of COMPRESS-504 and COMPRESS-505
This is an automated email from the ASF dual-hosted git repository. peterlee 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 ff5782a update changes of COMPRESS-504 and COMPRESS-505 ff5782a is described below commit ff5782a89d44d731bda560ae5938d6603d57deb5 Author: PeterAlfredLee AuthorDate: Fri Apr 17 10:00:42 2020 +0800 update changes of COMPRESS-504 and COMPRESS-505 --- src/changes/changes.xml | 10 ++ 1 file changed, 10 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 39dcff6..5247a15 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -50,6 +50,16 @@ The type attribute can be add,update,fix,remove. deprecated ZstOutputStream constructors. Github Pull Request #94. + +Make compression level of ParallelScatterZipCreator +configurable via a new constructor. + + +Fix bugs in random access of 7z. Problems may happen +in a mixture use of random access and sequential access +of 7z. +Github Pull Request #95. +
[commons-compress] branch master updated: update changes of COMPRESS-504 and COMPRESS-505
This is an automated email from the ASF dual-hosted git repository. peterlee 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 ff5782a update changes of COMPRESS-504 and COMPRESS-505 ff5782a is described below commit ff5782a89d44d731bda560ae5938d6603d57deb5 Author: PeterAlfredLee AuthorDate: Fri Apr 17 10:00:42 2020 +0800 update changes of COMPRESS-504 and COMPRESS-505 --- src/changes/changes.xml | 10 ++ 1 file changed, 10 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 39dcff6..5247a15 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -50,6 +50,16 @@ The type attribute can be add,update,fix,remove. deprecated ZstOutputStream constructors. Github Pull Request #94. + +Make compression level of ParallelScatterZipCreator +configurable via a new constructor. + + +Fix bugs in random access of 7z. Problems may happen +in a mixture use of random access and sequential access +of 7z. +Github Pull Request #95. +
[commons-compress] branch master updated: COMPRESS-510 : fix multiple retrievals of first entry of 7z
This is an automated email from the ASF dual-hosted git repository. peterlee 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 1e6fd14 COMPRESS-510 : fix multiple retrievals of first entry of 7z 1e6fd14 is described below commit 1e6fd140c081fc50b62c628bec259f2d88417ebf Author: PeterAlfredLee AuthorDate: Sat Apr 18 14:54:03 2020 +0800 COMPRESS-510 : fix multiple retrievals of first entry of 7z Multiple retrievals of InputStream for same SevenZFile entry fails --- src/changes/changes.xml | 5 + .../apache/commons/compress/archivers/sevenz/SevenZFile.java | 5 +++-- .../commons/compress/archivers/sevenz/SevenZFileTest.java | 11 +++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 5247a15..90804e8 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -60,6 +60,11 @@ The type attribute can be add,update,fix,remove. of 7z. Github Pull Request #95. + +Fix bugs in random access of 7z. Exceptions are thrown +when reading the first entry multiable times by random +access. + diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java index 2a1d7f9..04a01e8 100644 --- a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java +++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java @@ -1179,8 +1179,9 @@ public class SevenZFile implements Closeable { // previous stream has to be fully decoded before we can start reading // but don't do it eagerly -- if the user skips over the entire folder nothing // is effectively decompressed. - -file.setContentMethods(archive.files[entryIndex - 1].getContentMethods()); +if (entryIndex > 0) { +file.setContentMethods(archive.files[entryIndex - 1].getContentMethods()); +} // if this is called in a random access, then the content methods of previous entry may be null // the content methods should be set to methods of the first entry as it must not be null, diff --git a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java index c47904b..68b478c 100644 --- a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java @@ -673,6 +673,17 @@ public class SevenZFileTest extends AbstractTestCase { } } +@Test +public void retrieveInputStreamForAllEntriesMultipleTimes() throws IOException { +try (SevenZFile sevenZFile = new SevenZFile(getFile("bla.7z"))) { +for (SevenZArchiveEntry entry : sevenZFile.getEntries()) { +byte[] firstRead = IOUtils.toByteArray(sevenZFile.getInputStream(entry)); +byte[] secondRead = IOUtils.toByteArray(sevenZFile.getInputStream(entry)); +assertArrayEquals(firstRead, secondRead); +} +} +} + private void test7zUnarchive(final File f, final SevenZMethod m, final byte[] password) throws Exception { try (SevenZFile sevenZFile = new SevenZFile(f, password)) { test7zUnarchive(sevenZFile, m);
[commons-compress] branch master updated: COMPRESS-510 : fix for multiple retrievals of InputStream for same SevenZFile entry fails
This is an automated email from the ASF dual-hosted git repository. peterlee 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 69de512 COMPRESS-510 : fix for multiple retrievals of InputStream for same SevenZFile entry fails 69de512 is described below commit 69de512db43c9ca35da11664a1502702353a6fdd Author: PeterAlfredLee AuthorDate: Wed Apr 22 11:08:22 2020 +0800 COMPRESS-510 : fix for multiple retrievals of InputStream for same SevenZFile entry fails fix for multiple retrievals of InputStream for same SevenZFile entry fails --- src/changes/changes.xml| 2 +- .../compress/archivers/sevenz/SevenZFile.java | 47 +- .../commons/compress/utils/BoundedInputStream.java | 8 .../utils/ChecksumVerifyingInputStream.java| 4 ++ .../compress/archivers/sevenz/SevenZFileTest.java | 24 +++ 5 files changed, 65 insertions(+), 20 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 90804e8..4ebd470 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -62,7 +62,7 @@ The type attribute can be add,update,fix,remove. Fix bugs in random access of 7z. Exceptions are thrown -when reading the first entry multiable times by random +when reading the first entry multiple times by random access. diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java index 04a01e8..5de9667 100644 --- a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java +++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java @@ -1267,25 +1267,9 @@ public class SevenZFile implements Closeable { */ private boolean skipEntriesWhenNeeded(int entryIndex, boolean isInSameFolder, int folderIndex) throws IOException { final SevenZArchiveEntry file = archive.files[entryIndex]; -final boolean isNeedToSkipEntries; -boolean hasCurrentEntryBeenRead = false; -if (currentEntryIndex != entryIndex) { -// this means there are some entries to be skipped(currentEntryIndex < entryIndex) -// or the entry has already been read(currentEntryIndex > entryIndex) -isNeedToSkipEntries = true; -} else { -if (deferredBlockStreams.size() > 0) { -CRC32VerifyingInputStream currentEntryInputStream = (CRC32VerifyingInputStream) deferredBlockStreams.get(deferredBlockStreams.size() - 1); -hasCurrentEntryBeenRead = currentEntryInputStream.getBytesRemaining() != archive.files[currentEntryIndex].getSize(); -} - -// if the entry to be read is the current entry, but some data of it has -// been read before, then we need to reopen the stream of the folder and -// skip all the entries before the current entries -isNeedToSkipEntries = hasCurrentEntryBeenRead; -} - -if (!isNeedToSkipEntries) { +// if the entry to be read is the current entry, and the entry has not +// been read yet, then there's nothing we need to do +if (currentEntryIndex == entryIndex && !hasCurrentEntryBeenRead()) { return false; } @@ -1321,6 +1305,31 @@ public class SevenZFile implements Closeable { return true; } +/** + * Find out if any data of current entry has been read or not. + * This is achieved by comparing the bytes remaining to read + * and the size of the file. + * + * @return true if any data of current entry has been read + * @since 1.21 + */ +private boolean hasCurrentEntryBeenRead() { +boolean hasCurrentEntryBeenRead = false; +if (deferredBlockStreams.size() > 0) { +InputStream currentEntryInputStream = deferredBlockStreams.get(deferredBlockStreams.size() - 1); +// get the bytes remaining to read, and compare it with the size of +// the file to figure out if the file has been read +if (currentEntryInputStream instanceof CRC32VerifyingInputStream) { +hasCurrentEntryBeenRead = ((CRC32VerifyingInputStream) currentEntryInputStream).getBytesRemaining() != archive.files[currentEntryIndex].getSize(); +} + +if (currentEntryInputStream instanceof BoundedInputStream) { +hasCurrentEntryBeenRead = ((BoundedInputStream) currentEntryInputStream).getBytesRemaining() != archive.files[currentEntryIndex].getSize(); +} +} +return hasCurrentEntryBeenRead; +} + private InputStream buildDecoderStack(final Folder folder, final long folderOffset,
[commons-compress] branch master updated: COMPRESS-509 : add '/' to directories with long name in tar
This is an automated email from the ASF dual-hosted git repository. peterlee 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 7cb298d COMPRESS-509 : add '/' to directories with long name in tar 7cb298d is described below commit 7cb298d943ec1a2811f1472824b7724d580a9217 Author: PeterAlfredLee AuthorDate: Wed May 6 16:32:58 2020 +0800 COMPRESS-509 : add '/' to directories with long name in tar Resolve the ambiguous behavior of the TarArchiveEntry.getName() method between directory with short name and long name. And improve the imports of some test classes. --- .../archivers/tar/TarArchiveInputStream.java | 8 ++- .../commons/compress/archivers/TarTestCase.java| 6 ++- .../archivers/tar/TarArchiveEntryTest.java | 2 - .../archivers/tar/TarArchiveInputStreamTest.java | 59 -- 4 files changed, 67 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java index c02beda..716718d 100644 --- a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java @@ -393,7 +393,13 @@ public class TarArchiveInputStream extends ArchiveInputStream { // entry return null; } -currEntry.setName(zipEncoding.decode(longNameData)); + +// COMPRESS-509 : the name of directories should end with '/' +String name = zipEncoding.decode(longNameData); +if (currEntry.isDirectory() && !name.endsWith("/")) { +name += "/"; +} +currEntry.setName(name); } if (currEntry.isGlobalPaxHeader()){ // Process Global Pax headers diff --git a/src/test/java/org/apache/commons/compress/archivers/TarTestCase.java b/src/test/java/org/apache/commons/compress/archivers/TarTestCase.java index 19fa51a..27c1e9a 100644 --- a/src/test/java/org/apache/commons/compress/archivers/TarTestCase.java +++ b/src/test/java/org/apache/commons/compress/archivers/TarTestCase.java @@ -18,7 +18,11 @@ */ package org.apache.commons.compress.archivers; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.io.File; import java.io.FileInputStream; diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java index 703d3a4..54b372e 100644 --- a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java @@ -32,8 +32,6 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; -import java.io.InputStreamReader; -import java.io.Reader; import java.util.Locale; import org.apache.commons.compress.AbstractTestCase; import org.junit.Test; diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java index 661e66b..b1cee11 100644 --- a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java @@ -18,9 +18,6 @@ package org.apache.commons.compress.archivers.tar; -import static org.apache.commons.compress.AbstractTestCase.getFile; -import static org.apache.commons.compress.AbstractTestCase.mkdir; -import static org.apache.commons.compress.AbstractTestCase.rmdir; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -28,6 +25,7 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.io.BufferedOutputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; @@ -41,12 +39,15 @@ import java.util.Map; import java.util.TimeZone; import java.util.zip.GZIPInputStream; +import org.apache.commons.compress.AbstractTestCase; import org.apache.commons.compress.archivers.ArchiveEntry; +import org.apache.commons.compress.archivers.ArchiveException; +import org.apache.commons.compress.archivers.ArchiveStreamFactory; impo
[commons-compress] branch master updated: Remove deprecated sudo setting.
This is an automated email from the ASF dual-hosted git repository. peterlee 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 54f6b94 Remove deprecated sudo setting. new d1b59e9 Merge pull request #99 from dengliming/patch-1 54f6b94 is described below commit 54f6b94310fc8ab64ea7d064aeee370a823b44fd Author: dengliming AuthorDate: Tue May 12 21:44:44 2020 +0800 Remove deprecated sudo setting. --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8760635..6a24123 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -sudo: false language: java matrix:
[commons-compress] branch master updated (a5ccbd6 -> 6caf07a)
This is an automated email from the ASF dual-hosted git repository. peterlee pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git. from a5ccbd6 typos - and also mention "cannot build" as general limitation new f2a7a60 more descriptive error message in zipFile ctor new 40c4d36 reformat Zipfile error message new a468436 Fixes new fe36839 removing extra whitespace new 636660f Removed extraneous error message new 6caf07a Merge pull request #102 from ian-lavallee/master The 2893 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference. Summary of changes: src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java | 2 ++ 1 file changed, 2 insertions(+)
[commons-compress] branch master updated: fix minor errors in test
This is an automated email from the ASF dual-hosted git repository. peterlee 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 8f9e2e5 fix minor errors in test 8f9e2e5 is described below commit 8f9e2e5aa9a059076361cb31c98ef7434eae4c28 Author: PeterAlfredLee AuthorDate: Sat May 23 15:55:45 2020 +0800 fix minor errors in test --- .../java/org/apache/commons/compress/archivers/zip/ZipFileTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java index 3da2510..b8b8e66 100644 --- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java @@ -904,7 +904,7 @@ public class ZipFileTest { String tempLineInFile2; for(int i = 0;i < linesOfFile1.size();i++) { tempLineInFile1 = linesOfFile1.get(i).replaceAll("\r\n", "\n"); -tempLineInFile2 = linesOfFile1.get(i).replaceAll("\r\n", "\n"); +tempLineInFile2 = linesOfFile2.get(i).replaceAll("\r\n", "\n"); Assert.assertEquals(tempLineInFile1, tempLineInFile2); } }
[commons-compress] branch master updated: COMPRESS-515 : add COMPRESS-515 in changes
This is an automated email from the ASF dual-hosted git repository. peterlee 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 706c06e COMPRESS-515 : add COMPRESS-515 in changes 706c06e is described below commit 706c06e41f59e1806e7473df93246fdcd3c872c7 Author: PeterAlfredLee AuthorDate: Sun May 24 22:14:06 2020 +0800 COMPRESS-515 : add COMPRESS-515 in changes --- src/changes/changes.xml | 5 + 1 file changed, 5 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index fb47c04..3d59838 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -91,6 +91,11 @@ The type attribute can be add,update,fix,remove. RuntimeExceptions. See also COMPRESS-522, COMPRESS-525, COMPRESS-526, and COMPRESS-527. + +Add the archive name in the exception in the constructor of +ZipFIle to make it a more specific exception. +Github Pull Request #102. +
[commons-compress] branch master updated: COMPRESS-530 : skip non-number when parsing pax header
This is an automated email from the ASF dual-hosted git repository. peterlee 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 d5d9862 COMPRESS-530 : skip non-number when parsing pax header d5d9862 is described below commit d5d9862870e1c7e7110418d97665fdda717babad Author: PeterAlfredLee AuthorDate: Tue May 26 20:28:37 2020 +0800 COMPRESS-530 : skip non-number when parsing pax header --- .../compress/archivers/tar/TarArchiveInputStream.java | 6 ++ .../compress/archivers/tar/TarArchiveInputStreamTest.java | 9 + src/test/resources/COMPRESS-530.tar | Bin 0 -> 525 bytes 3 files changed, 15 insertions(+) diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java index 716718d..45f6b89 100644 --- a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java @@ -745,6 +745,12 @@ public class TarArchiveInputStream extends ArchiveInputStream { } break; // Processed single header } + +// COMPRESS-530 : skip non-number chars +if (ch < '0' || ch > '9') { +continue; +} + len *= 10; len += ch - '0'; } diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java index b1cee11..095ec2c 100644 --- a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java @@ -424,6 +424,15 @@ public class TarArchiveInputStreamTest extends AbstractTestCase { } } +@Test(expected = IOException.class) +public void testParseTarWithSpecialPaxHeaders() throws IOException { +try (FileInputStream in = new FileInputStream(getFile("COMPRESS-530.tar")); + TarArchiveInputStream archive = new TarArchiveInputStream(in)) { +archive.getNextEntry(); +IOUtils.toByteArray(archive); +} +} + private TarArchiveInputStream getTestStream(final String name) { return new TarArchiveInputStream( TarArchiveInputStreamTest.class.getResourceAsStream(name)); diff --git a/src/test/resources/COMPRESS-530.tar b/src/test/resources/COMPRESS-530.tar new file mode 100644 index 000..63f6780 Binary files /dev/null and b/src/test/resources/COMPRESS-530.tar differ
[commons-compress] branch master updated: COMPRESS-530 : and record in changes.xml
This is an automated email from the ASF dual-hosted git repository. peterlee 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 ae0a15c COMPRESS-530 : and record in changes.xml ae0a15c is described below commit ae0a15cc301e827a6139af03bfe911c2f919a47c Author: PeterAlfredLee AuthorDate: Tue May 26 20:42:22 2020 +0800 COMPRESS-530 : and record in changes.xml --- src/changes/changes.xml | 5 - 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 3d59838..b97 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -91,11 +91,14 @@ The type attribute can be add,update,fix,remove. RuntimeExceptions. See also COMPRESS-522, COMPRESS-525, COMPRESS-526, and COMPRESS-527. - + Add the archive name in the exception in the constructor of ZipFIle to make it a more specific exception. Github Pull Request #102. + +Skip non-number chars while parsing pax headers. +
[commons-compress] branch master updated: COMPRESS-529 : throws IOException if non-number exists in pax header
This is an automated email from the ASF dual-hosted git repository. peterlee 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 b8a0b54 COMPRESS-529 : throws IOException if non-number exists in pax header b8a0b54 is described below commit b8a0b54c59191cb8338585eab055897737730a9e Author: PeterAlfredLee AuthorDate: Tue May 26 21:11:54 2020 +0800 COMPRESS-529 : throws IOException if non-number exists in pax header Throws IOException with more specific info when parsing a non-number value while parsing pax headers. --- src/changes/changes.xml| 4 + .../compress/archivers/tar/TarArchiveEntry.java| 115 +++-- .../archivers/tar/TarArchiveInputStream.java | 3 +- .../archivers/tar/TarArchiveInputStreamTest.java | 9 ++ src/test/resources/COMPRESS-529.tar| Bin 0 -> 1536 bytes 5 files changed, 78 insertions(+), 53 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index b97..ec51a84 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -96,6 +96,10 @@ The type attribute can be add,update,fix,remove. ZipFIle to make it a more specific exception. Github Pull Request #102. + +Throws IOException with more specific info when parsing a +non-number value while parsing pax headers. + Skip non-number chars while parsing pax headers. 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 f180780..87acace 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 @@ -1063,12 +1063,14 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants { /** * add a PAX header to this entry. If the header corresponds to an existing field in the entry, * that field will be set; otherwise the header will be added to the extraPaxHeaders Map + * * @param name The full name of the header to set. * @param value value of header. + * @throws IOException if error occurs when parsing pax header * @since 1.15 */ -public void addPaxHeader(String name,String value) { - processPaxHeader(name,value); +public void addPaxHeader(String name, String value) throws IOException { +processPaxHeader(name, value); } /** @@ -1083,10 +1085,12 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants { /** * Update the entry using a map of pax headers. + * * @param headers + * @throws IOException if error occurs when parsing pax header * @since 1.15 */ -void updateEntryFromPaxHeaders(Map headers) { +void updateEntryFromPaxHeaders(Map headers) throws IOException { for (final Map.Entry ent : headers.entrySet()) { final String key = ent.getKey(); final String val = ent.getValue(); @@ -1097,11 +1101,13 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants { /** * process one pax header, using the entries extraPaxHeaders map as source for extra headers * used when handling entries for sparse files. + * * @param key * @param val + * @throws IOException if error occurs when parsing pax header * @since 1.15 */ -private void processPaxHeader(String key, String val) { +private void processPaxHeader(String key, String val) throws IOException { processPaxHeader(key,val,extraPaxHeaders); } @@ -1109,12 +1115,13 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants { * Process one pax header, using the supplied map as source for extra headers to be used when handling * entries for sparse files * - * @param key the header name. - * @param val the header value. - * @param headers map of headers used for dealing with sparse file. + * @param key the header name. + * @param val the header value. + * @param headers map of headers used for dealing with sparse file. + * @throws IOException if error occurs when parsing pax header * @since 1.15 */ -private void processPaxHeader(String key, String val, Map headers) { +private void processPaxHeader(String key, String val, Map headers) throws IOException { /* * The following headers are defined for Pax. * atime, ctime, charset: cannot use these without changing TarArchiveEntry fields @@ -1135,50 +1142,54 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants { * * If called from addExtraPaxHeader, these additional headers must
[commons-compress] branch master updated: Revert "COMPRESS-529 : throws IOException if non-number exists in pax header"
This is an automated email from the ASF dual-hosted git repository. peterlee 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 8d969d6 Revert "COMPRESS-529 : throws IOException if non-number exists in pax header" 8d969d6 is described below commit 8d969d60536b8878f73fd494c517de5d18be9d89 Author: PeterAlfredLee AuthorDate: Wed May 27 20:44:12 2020 +0800 Revert "COMPRESS-529 : throws IOException if non-number exists in pax header" This reverts commit b8a0b54c59191cb8338585eab055897737730a9e. --- src/changes/changes.xml| 4 - .../compress/archivers/tar/TarArchiveEntry.java| 115 ++--- .../archivers/tar/TarArchiveInputStream.java | 3 +- .../archivers/tar/TarArchiveInputStreamTest.java | 9 -- src/test/resources/COMPRESS-529.tar| Bin 1536 -> 0 bytes 5 files changed, 53 insertions(+), 78 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index ec51a84..b97 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -96,10 +96,6 @@ The type attribute can be add,update,fix,remove. ZipFIle to make it a more specific exception. Github Pull Request #102. - -Throws IOException with more specific info when parsing a -non-number value while parsing pax headers. - Skip non-number chars while parsing pax headers. 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 87acace..f180780 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 @@ -1063,14 +1063,12 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants { /** * add a PAX header to this entry. If the header corresponds to an existing field in the entry, * that field will be set; otherwise the header will be added to the extraPaxHeaders Map - * * @param name The full name of the header to set. * @param value value of header. - * @throws IOException if error occurs when parsing pax header * @since 1.15 */ -public void addPaxHeader(String name, String value) throws IOException { -processPaxHeader(name, value); +public void addPaxHeader(String name,String value) { + processPaxHeader(name,value); } /** @@ -1085,12 +1083,10 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants { /** * Update the entry using a map of pax headers. - * * @param headers - * @throws IOException if error occurs when parsing pax header * @since 1.15 */ -void updateEntryFromPaxHeaders(Map headers) throws IOException { +void updateEntryFromPaxHeaders(Map headers) { for (final Map.Entry ent : headers.entrySet()) { final String key = ent.getKey(); final String val = ent.getValue(); @@ -1101,13 +1097,11 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants { /** * process one pax header, using the entries extraPaxHeaders map as source for extra headers * used when handling entries for sparse files. - * * @param key * @param val - * @throws IOException if error occurs when parsing pax header * @since 1.15 */ -private void processPaxHeader(String key, String val) throws IOException { +private void processPaxHeader(String key, String val) { processPaxHeader(key,val,extraPaxHeaders); } @@ -1115,13 +1109,12 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants { * Process one pax header, using the supplied map as source for extra headers to be used when handling * entries for sparse files * - * @param key the header name. - * @param val the header value. - * @param headers map of headers used for dealing with sparse file. - * @throws IOException if error occurs when parsing pax header + * @param key the header name. + * @param val the header value. + * @param headers map of headers used for dealing with sparse file. * @since 1.15 */ -private void processPaxHeader(String key, String val, Map headers) throws IOException { +private void processPaxHeader(String key, String val, Map headers) { /* * The following headers are defined for Pax. * atime, ctime, charset: cannot use these without changing TarArchiveEntry fields @@ -1142,54 +1135,50 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants { * * If called from addExtraPaxHeader, these additional headers m
[commons-compress] branch master updated: COMPRESS-530 : throw IOException instead
This is an automated email from the ASF dual-hosted git repository. peterlee 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 5e02ee7 COMPRESS-530 : throw IOException instead 5e02ee7 is described below commit 5e02ee762b8443187b74801e18eddb845fec48db Author: PeterAlfredLee AuthorDate: Wed May 27 21:57:23 2020 +0800 COMPRESS-530 : throw IOException instead Throw an IOException instead of skipping it if it encounters a non-number while reading length in pax header. --- src/changes/changes.xml | 2 +- .../apache/commons/compress/archivers/tar/TarArchiveInputStream.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index b97..6eb4141 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -97,7 +97,7 @@ The type attribute can be add,update,fix,remove. Github Pull Request #102. -Skip non-number chars while parsing pax headers. +Throw IOException when it encounters a non-number while parsing pax header. '9') { -continue; +throw new IOException("Failed to read Paxheader. Encounter a non-number while reading length"); } len *= 10;
[commons-compress] branch master updated: COMPRESS-529 : properly throw Exceptions for tar
This is an automated email from the ASF dual-hosted git repository. peterlee 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 36773d9 COMPRESS-529 : properly throw Exceptions for tar 36773d9 is described below commit 36773d948e9a220c1dc3abec3d2028b0879a7766 Author: PeterAlfredLee AuthorDate: Mon Jun 1 16:48:05 2020 +0800 COMPRESS-529 : properly throw Exceptions for tar Throw expected IOException instead of NumberFormatException if it encounters non-numbers in tar pax headers. Throw IllegalArgumentException if the file name is too long with the default long file mode LONGFILE_ERROR --- src/changes/changes.xml | 8 .../commons/compress/archivers/tar/TarArchiveEntry.java | 1 + .../compress/archivers/tar/TarArchiveInputStream.java| 12 .../compress/archivers/tar/TarArchiveOutputStream.java | 5 - .../archivers/tar/TarArchiveInputStreamTest.java | 8 .../archivers/tar/TarArchiveOutputStreamTest.java| 10 ++ src/test/resources/COMPRESS-529.tar | Bin 0 -> 1536 bytes 7 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 9c6d8b5..0c0e3f2 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -108,6 +108,14 @@ The type attribute can be add,update,fix,remove. throw the expected IOException rather than obscure RuntimeExceptions. + +Throw expected IOException instead of NumberFormatException if +it encounters non-numbers when parsing pax headers for tarball. + +Throw IllegalArgumentException instead of RuntimeExceptions if +the file name is longer than 100 bytes with the longFileMode +of LONGFILE_ERROR, and address this in java docs. + 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 f180780..d562336 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 @@ -1112,6 +1112,7 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants { * @param key the header name. * @param val the header value. * @param headers map of headers used for dealing with sparse file. + * @throws NumberFormatException if encountered errors when parsing the numbers * @since 1.15 */ private void processPaxHeader(String key, String val, Map headers) { diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java index c112ac7..320fc9d 100644 --- a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java @@ -406,10 +406,14 @@ public class TarArchiveInputStream extends ArchiveInputStream { readGlobalPaxHeaders(); } -if (currEntry.isPaxHeader()){ // Process Pax headers -paxHeaders(); -} else if (!globalPaxHeaders.isEmpty()) { -applyPaxHeadersToCurrentEntry(globalPaxHeaders, globalSparseHeaders); +try { +if (currEntry.isPaxHeader()){ // Process Pax headers +paxHeaders(); +} else if (!globalPaxHeaders.isEmpty()) { +applyPaxHeadersToCurrentEntry(globalPaxHeaders, globalSparseHeaders); +} +} catch (NumberFormatException e) { +throw new IOException("Error detected parsing the pax header", e); } if (currEntry.isOldGNUSparse()){ // Process sparse files diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java index 758f673..0816976 100644 --- a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java @@ -654,6 +654,9 @@ public class TarArchiveOutputStream extends ArchiveOutputStream { * @param paxHeaderName name of the pax header to write * @param linkType type of the GNU entry to write * @param fieldName the name of the field + * @throws IllegalArgumentException if the {@link TarArchiveOutputStream#longFileMode} equals + * {@link TarArchiveOutputStream#LONGFILE_ERROR} and the file + * name is too long * @return whether
[commons-compress] branch master updated: typos
This is an automated email from the ASF dual-hosted git repository. peterlee 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 b13c931 typos b13c931 is described below commit b13c93182365253fc16a1bac4d46ad6e946bf568 Author: PeterAlfredLee AuthorDate: Mon Jun 1 16:52:37 2020 +0800 typos --- src/changes/changes.xml | 2 +- .../apache/commons/compress/archivers/tar/TarArchiveInputStream.java| 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 0c0e3f2..1c05cd1 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -101,7 +101,7 @@ The type attribute can be add,update,fix,remove. Throw IOException when a a tar archive contains a PAX header -without any normal entry follwoing it. +without any normal entry following it. Added improved checks to detect corrupted IMPLODED streams and diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java index 320fc9d..618e4d1 100644 --- a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java @@ -682,7 +682,7 @@ public class TarArchiveInputStream extends ArchiveInputStream { * GNU.sparse.map *Map of non-null data chunks. It is a string consisting of comma-separated values "offset,size[,offset-1,size-1...]" * - * @param inputstream inputstream to read keys and values + * @param inputStream inputStream to read keys and values * @param sparseHeaders used in PAX Format 0.0 & 0.1, as it may appear multi times, * the sparse headers need to be stored in an array, not a map * @return map of PAX headers values found inside of the current (local or global) PAX headers tar entry.
[commons-compress] branch master updated: minor typos cleanup
This is an automated email from the ASF dual-hosted git repository. peterlee 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 42b6aa4 minor typos cleanup 42b6aa4 is described below commit 42b6aa4c8a097f2ed49eb51b9fac61e7f8033cb2 Author: PeterAlfredLee AuthorDate: Mon Jun 1 21:00:53 2020 +0800 minor typos cleanup --- .../apache/commons/compress/archivers/tar/TarArchiveOutputStream.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java index 07b3e69..e4b0c2d 100644 --- a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java @@ -335,9 +335,6 @@ public class TarArchiveOutputStream extends ArchiveOutputStream { * @param archiveEntry The TarEntry to be written to the archive. * @throws IOException on error * @throws ClassCastException if archiveEntry is not an instance of TarArchiveEntry - * @throws IllegalArgumentException if the {@link TarArchiveOutputStream#longFileMode} equals - * {@link TarArchiveOutputStream#LONGFILE_ERROR} and the file - * name is too long * @throws IllegalArgumentException if the {@link TarArchiveOutputStream#bigNumberMode} equals * {@link TarArchiveOutputStream#BIGNUMBER_ERROR} and one of the numeric values * exceeds the limits of a traditional tar header.
[commons-compress] branch master updated: restore error deleted throws declaration
This is an automated email from the ASF dual-hosted git repository. peterlee 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 6374698 restore error deleted throws declaration 6374698 is described below commit 637469893b0ade91d8bca61c25e0e9282f977213 Author: PeterAlfredLee AuthorDate: Tue Jun 2 09:55:41 2020 +0800 restore error deleted throws declaration --- .../apache/commons/compress/archivers/tar/TarArchiveOutputStream.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java index e4b0c2d..07b3e69 100644 --- a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java @@ -335,6 +335,9 @@ public class TarArchiveOutputStream extends ArchiveOutputStream { * @param archiveEntry The TarEntry to be written to the archive. * @throws IOException on error * @throws ClassCastException if archiveEntry is not an instance of TarArchiveEntry + * @throws IllegalArgumentException if the {@link TarArchiveOutputStream#longFileMode} equals + * {@link TarArchiveOutputStream#LONGFILE_ERROR} and the file + * name is too long * @throws IllegalArgumentException if the {@link TarArchiveOutputStream#bigNumberMode} equals * {@link TarArchiveOutputStream#BIGNUMBER_ERROR} and one of the numeric values * exceeds the limits of a traditional tar header.
[commons-compress] branch master updated: unitized array styles.
This is an automated email from the ASF dual-hosted git repository. peterlee 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 774f6b4 unitized array styles. new e587f09 Merge pull request #109 from XenoAmess/array_style 774f6b4 is described below commit 774f6b41a46fd7ddd2196687115569729646a67a Author: XenoAmess AuthorDate: Fri Jun 5 03:46:38 2020 +0800 unitized array styles. --- .../compress/archivers/cpio/CpioArchiveInputStream.java | 8 .../compress/archivers/cpio/CpioArchiveOutputStream.java | 4 ++-- .../org/apache/commons/compress/archivers/cpio/CpioUtil.java | 2 +- .../apache/commons/compress/archivers/sevenz/SevenZFile.java | 2 +- .../compress/archivers/zip/X0017_StrongEncryptionHeader.java | 12 ++-- .../org/apache/commons/compress/compressors/bzip2/CRC.java | 2 +- .../apache/commons/compress/archivers/tar/TarUtilsTest.java | 4 ++-- .../compress/compressors/bzip2/PythonTruncatedBzip2Test.java | 2 +- .../compress/utils/FixedLengthBlockOutputStreamTest.java | 6 +++--- 9 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java index bec56e5..09d1def 100644 --- a/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java @@ -75,7 +75,7 @@ public class CpioArchiveInputStream extends ArchiveInputStream implements private boolean entryEOF = false; -private final byte tmpbuf[] = new byte[4096]; +private final byte[] tmpbuf = new byte[4096]; private long crc = 0; @@ -355,14 +355,14 @@ public class CpioArchiveInputStream extends ArchiveInputStream implements private long readBinaryLong(final int length, final boolean swapHalfWord) throws IOException { -final byte tmp[] = new byte[length]; +final byte[] tmp = new byte[length]; readFully(tmp, 0, tmp.length); return CpioUtil.byteArray2long(tmp, swapHalfWord); } private long readAsciiLong(final int length, final int radix) throws IOException { -final byte tmpBuffer[] = new byte[length]; +final byte[] tmpBuffer = new byte[length]; readFully(tmpBuffer, 0, tmpBuffer.length); return Long.parseLong(ArchiveUtils.toAsciiString(tmpBuffer), radix); } @@ -480,7 +480,7 @@ public class CpioArchiveInputStream extends ArchiveInputStream implements private String readCString(final int length) throws IOException { // don't include trailing NUL in file name to decode -final byte tmpBuffer[] = new byte[length - 1]; +final byte[] tmpBuffer = new byte[length - 1]; readFully(tmpBuffer, 0, tmpBuffer.length); if (this.in.read() == -1) { throw new EOFException(); diff --git a/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java b/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java index 8df75c3..cb15410 100644 --- a/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java @@ -500,7 +500,7 @@ public class CpioArchiveOutputStream extends ArchiveOutputStream implements private void pad(final int count) throws IOException{ if (count > 0){ -final byte buff[] = new byte[count]; +final byte[] buff = new byte[count]; out.write(buff); count(count); } @@ -508,7 +508,7 @@ public class CpioArchiveOutputStream extends ArchiveOutputStream implements private void writeBinaryLong(final long number, final int length, final boolean swapHalfWord) throws IOException { -final byte tmp[] = CpioUtil.long2byteArray(number, length, swapHalfWord); +final byte[] tmp = CpioUtil.long2byteArray(number, length, swapHalfWord); out.write(tmp); count(tmp.length); } diff --git a/src/main/java/org/apache/commons/compress/archivers/cpio/CpioUtil.java b/src/main/java/org/apache/commons/compress/archivers/cpio/CpioUtil.java index f53ea44..234d49d 100644 --- a/src/main/java/org/apache/commons/compress/archivers/cpio/CpioUtil.java +++ b/src/main/java/org/apache/commons/compress/archivers/cpio/CpioUtil.java @@ -50,7 +50,7 @@ class CpioUtil { long ret = 0; int pos = 0; -final byte tmp_number[] = new byte[number.length]; +final byte[] tmp_number = new byte[number.length]; System.arraycopy(number, 0, tmp_number, 0, number.length); if (!swap
[commons-compress] branch master updated: remove unused imports.
This is an automated email from the ASF dual-hosted git repository. peterlee 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 932fbdb remove unused imports. new eb79e1a Merge pull request #111 from XenoAmess/remove_unused_imports 932fbdb is described below commit 932fbdbfaf1604e24d2f95028e187c8eea23a7f7 Author: XenoAmess AuthorDate: Fri Jun 5 03:52:36 2020 +0800 remove unused imports. --- .../java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java | 1 - .../apache/commons/compress/archivers/tar/TarArchiveOutputStream.java | 1 - .../commons/compress/archivers/zip/AbstractUnicodeExtraField.java | 3 --- .../commons/compress/compressors/gzip/GzipCompressorInputStream.java | 1 - .../commons/compress/compressors/gzip/GzipCompressorOutputStream.java | 1 - src/main/java/org/apache/commons/compress/utils/ArchiveUtils.java | 1 - .../commons/compress/archivers/examples/ParameterizedExpanderTest.java | 1 - .../org/apache/commons/compress/archivers/tar/SparseFilesTest.java | 1 - .../commons/compress/archivers/tar/TarArchiveOutputStreamTest.java | 1 - .../java/org/apache/commons/compress/archivers/zip/ZipFileTest.java| 1 - .../apache/commons/compress/utils/SeekableInMemoryByteChannelTest.java | 2 -- 11 files changed, 14 deletions(-) diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java index d331f65..f4ee9c7 100644 --- a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java +++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java @@ -42,7 +42,6 @@ import java.util.zip.CRC32; import org.apache.commons.compress.utils.BoundedInputStream; import org.apache.commons.compress.utils.CRC32VerifyingInputStream; -import org.apache.commons.compress.utils.CharsetNames; import org.apache.commons.compress.utils.IOUtils; import org.apache.commons.compress.utils.InputStreamStatistics; diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java index d2f6b49..d44a18d 100644 --- a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java @@ -33,7 +33,6 @@ import org.apache.commons.compress.archivers.ArchiveEntry; import org.apache.commons.compress.archivers.ArchiveOutputStream; import org.apache.commons.compress.archivers.zip.ZipEncoding; import org.apache.commons.compress.archivers.zip.ZipEncodingHelper; -import org.apache.commons.compress.utils.CharsetNames; import org.apache.commons.compress.utils.CountingOutputStream; import org.apache.commons.compress.utils.FixedLengthBlockOutputStream; diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/AbstractUnicodeExtraField.java b/src/main/java/org/apache/commons/compress/archivers/zip/AbstractUnicodeExtraField.java index db88926..36b8872 100644 --- a/src/main/java/org/apache/commons/compress/archivers/zip/AbstractUnicodeExtraField.java +++ b/src/main/java/org/apache/commons/compress/archivers/zip/AbstractUnicodeExtraField.java @@ -18,13 +18,10 @@ package org.apache.commons.compress.archivers.zip; -import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; import java.util.zip.CRC32; import java.util.zip.ZipException; -import org.apache.commons.compress.utils.CharsetNames; - /** * A common base class for Unicode extra information extra fields. * @NotThreadSafe diff --git a/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java b/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java index b5b9bbe..4d7f742 100644 --- a/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java +++ b/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java @@ -33,7 +33,6 @@ import java.util.zip.CRC32; import org.apache.commons.compress.compressors.CompressorInputStream; import org.apache.commons.compress.utils.ByteUtils; -import org.apache.commons.compress.utils.CharsetNames; import org.apache.commons.compress.utils.CountingInputStream; import org.apache.commons.compress.utils.IOUtils; import org.apache.commons.compress.utils.InputStreamStatistics; diff --git a/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorOutputStream.java b/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorOutputStream.java index d7d27d6..2cf6d93 100644 --- a/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorOutputStream.java +++ b/src/main/java/org
[commons-compress] branch master updated: use System.currentTimeMillis instead of new Date().getTime
This is an automated email from the ASF dual-hosted git repository. peterlee 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 1cdf4ed use System.currentTimeMillis instead of new Date().getTime new a212dd4 Merge pull request #110 from XenoAmess/use_System_currentTimeMillis_insteadof_Date_getTime 1cdf4ed is described below commit 1cdf4eda2273473a9e046d0f0f9e3a984fedb63a Author: XenoAmess AuthorDate: Fri Jun 5 03:50:01 2020 +0800 use System.currentTimeMillis instead of new Date().getTime --- .../java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java | 2 +- 1 file changed, 1 insertion(+), 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 d562336..dfbe4ee 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 @@ -294,7 +294,7 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants { this.name = name; this.mode = isDir ? DEFAULT_DIR_MODE : DEFAULT_FILE_MODE; this.linkFlag = isDir ? LF_DIR : LF_NORMAL; -this.modTime = new Date().getTime() / MILLIS_PER_SECOND; +this.modTime = System.currentTimeMillis() / MILLIS_PER_SECOND; this.userName = ""; }
[commons-compress] branch master updated (a212dd4 -> 5964eb4)
This is an automated email from the ASF dual-hosted git repository. peterlee pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git. from a212dd4 Merge pull request #110 from XenoAmess/use_System_currentTimeMillis_insteadof_Date_getTime new 8f541a5 COMPRESS-404: Use java.nio.Path as backing object in TarArchiveEntry new 510d589 COMPRESS-404: Add owner information of file and gid/uid on linux to TarArchiveEntry new de37805 COMPRESS-404: Fix wrong cast for linux ids new afaaacf COMPRESS-404: Don't delegate the file constructor to the path constructor new a1d4ce6 COMPRESS-404: Fallback to old file api calls if new ones fail new 5964eb4 Merge pull request #97 from theobisproject/COMPRESS-404 The 2945 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference. Summary of changes: pom.xml| 6 + .../compress/archivers/tar/TarArchiveEntry.java| 185 ++--- .../apache/commons/compress/AbstractTestCase.java | 5 + .../archivers/tar/TarArchiveEntryTest.java | 41 + .../archivers/tar/TarMemoryFileSystemTest.java | 122 ++ 5 files changed, 332 insertions(+), 27 deletions(-) create mode 100644 src/test/java/org/apache/commons/compress/archivers/tar/TarMemoryFileSystemTest.java
[commons-compress] branch master updated: record PR#97 in changes.xml
This is an automated email from the ASF dual-hosted git repository. peterlee 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 8f056fe record PR#97 in changes.xml 8f056fe is described below commit 8f056fe9bc75f6ed7e07b7ea935176450cc8bf9e Author: PeterAlfredLee AuthorDate: Mon Jun 8 09:48:52 2020 +0800 record PR#97 in changes.xml --- src/changes/changes.xml | 6 ++ 1 file changed, 6 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 96410ee..3a1c189 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -121,6 +121,12 @@ The type attribute can be add,update,fix,remove. of a traditional tar header while bigNumberMode is BIGNUMBER_ERROR, and address this in java docs. + +Update the class of variable file in TarArchiveEntry from +java.io.File to java.nio.file.Path. Corresponding constructors +and methods are also modified/added. +Github Pull Request #97. +
[commons-compress] branch master updated: COMPRESS-539 : Update the IOUtils.skip to the latest implementation of Commons IO, and reuse the record buffer in TarArchiveInputStream.
This is an automated email from the ASF dual-hosted git repository. peterlee 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 101137b COMPRESS-539 : Update the IOUtils.skip to the latest implementation of Commons IO, and reuse the record buffer in TarArchiveInputStream. 101137b is described below commit 101137bfa0f3ae709c2a2771368b190ceb899ea0 Author: PeterAlfredLee AuthorDate: Sat Jul 4 19:11:41 2020 +0800 COMPRESS-539 : Update the IOUtils.skip to the latest implementation of Commons IO, and reuse the record buffer in TarArchiveInputStream. --- src/changes/changes.xml| 4 +++ .../archivers/tar/TarArchiveInputStream.java | 11 +++--- .../org/apache/commons/compress/utils/IOUtils.java | 42 +++--- 3 files changed, 32 insertions(+), 25 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 3a1c189..6247111 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -127,6 +127,10 @@ The type attribute can be add,update,fix,remove. and methods are also modified/added. Github Pull Request #97. + +Update the IOUtils.skip to the latest implementation of Commons +IO, and reuse the record buffer in TarArchiveInputStream. + diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java index 57bb601..bac1ee4 100644 --- a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java @@ -59,6 +59,9 @@ public class TarArchiveInputStream extends ArchiveInputStream { /** The size the TAR header */ private final int recordSize; +/** The buffer to store the TAR header **/ +private final byte[] recordBuffer; + /** The size of a block */ private final int blockSize; @@ -190,6 +193,7 @@ public class TarArchiveInputStream extends ArchiveInputStream { this.encoding = encoding; this.zipEncoding = ZipEncodingHelper.getZipEncoding(encoding); this.recordSize = recordSize; +this.recordBuffer = new byte[recordSize]; this.blockSize = blockSize; this.lenient = lenient; } @@ -519,16 +523,13 @@ public class TarArchiveInputStream extends ArchiveInputStream { * @throws IOException on error */ protected byte[] readRecord() throws IOException { - -final byte[] record = new byte[recordSize]; - -final int readNow = IOUtils.readFully(inputStream, record); +final int readNow = IOUtils.readFully(inputStream, recordBuffer); count(readNow); if (readNow != recordSize) { return null; } -return record; +return recordBuffer; } private void readGlobalPaxHeaders() throws IOException { diff --git a/src/main/java/org/apache/commons/compress/utils/IOUtils.java b/src/main/java/org/apache/commons/compress/utils/IOUtils.java index 7fa502a..f36070d 100644 --- a/src/main/java/org/apache/commons/compress/utils/IOUtils.java +++ b/src/main/java/org/apache/commons/compress/utils/IOUtils.java @@ -40,7 +40,7 @@ public final class IOUtils { // This buffer does not need to be synchronised because it is write only; the contents are ignored // Does not affect Immutability -private static final byte[] SKIP_BUF = new byte[SKIP_BUF_SIZE]; +private static byte[] SKIP_BUF; /** Private constructor to prevent instantiation of this utility class. */ private IOUtils(){ @@ -95,37 +95,39 @@ public final class IOUtils { * Skips the given number of bytes by repeatedly invoking skip on * the given input stream if necessary. * - * In a case where the stream's skip() method returns 0 before - * the requested number of bytes has been skip this implementation - * will fall back to using the read() method. - * * This method will only skip less than the requested number of * bytes if the end of the input stream has been reached. + * + * This method is copied from Apache Commons IO with commit ID + * of 401d17349e7ec52d8fa866c35efd24103f332c29 * - * @param input stream to skip bytes in + * @param input stream to skip bytes in * @param numToSkip the number of bytes to skip * @return the number of bytes actually skipped * @throws IOException on error */ public static long skip(final InputStream input, long numToSkip) throws IOException { -final long available = numToSkip; -while (numToSkip > 0) { -final long skipped = input.skip(numToSkip); -if (skipped == 0) { -
[commons-compress] branch master updated: COMPRESS-539 : revert the change to IOUtils.skip
This is an automated email from the ASF dual-hosted git repository. peterlee 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 893b441 COMPRESS-539 : revert the change to IOUtils.skip 893b441 is described below commit 893b441d761a445a65940b6fbd2dd5572516aa32 Author: PeterAlfredLee AuthorDate: Mon Jul 6 14:53:58 2020 +0800 COMPRESS-539 : revert the change to IOUtils.skip Revert the change to IOUtils.skip due to the performance. For specific information you can check the issue COMPRESS-449. --- src/changes/changes.xml| 3 +- .../org/apache/commons/compress/utils/IOUtils.java | 42 +++--- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 6247111..377e2e6 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -128,8 +128,7 @@ The type attribute can be add,update,fix,remove. Github Pull Request #97. -Update the IOUtils.skip to the latest implementation of Commons -IO, and reuse the record buffer in TarArchiveInputStream. +Reuse the record buffer in TarArchiveInputStream. In a case where the stream's skip() method returns 0 before + * the requested number of bytes has been skip this implementation + * will fall back to using the read() method. + * * This method will only skip less than the requested number of * bytes if the end of the input stream has been reached. - * - * This method is copied from Apache Commons IO with commit ID - * of 401d17349e7ec52d8fa866c35efd24103f332c29 * - * @param input stream to skip bytes in + * @param input stream to skip bytes in * @param numToSkip the number of bytes to skip * @return the number of bytes actually skipped * @throws IOException on error */ public static long skip(final InputStream input, long numToSkip) throws IOException { -if (numToSkip < 0) { -throw new IllegalArgumentException("Skip count must be non-negative, actual: " + numToSkip); -} -/* - * N.B. no need to synchronize this because: - we don't care if the buffer is created multiple times (the data - * is ignored) - we always use the same size buffer, so if it it is recreated it will still be OK (if the buffer - * size were variable, we would need to synch. to ensure some other thread did not create a smaller one) - */ -if (SKIP_BUF == null) { -SKIP_BUF = new byte[SKIP_BUF_SIZE]; +final long available = numToSkip; +while (numToSkip > 0) { +final long skipped = input.skip(numToSkip); +if (skipped == 0) { +break; +} +numToSkip -= skipped; } -long remain = numToSkip; -while (remain > 0) { -// See https://issues.apache.org/jira/browse/IO-203 for why we use read() rather than delegating to skip() -final long n = input.read(SKIP_BUF, 0, (int) Math.min(remain, SKIP_BUF_SIZE)); -if (n < 0) { // EOF + +while (numToSkip > 0) { +final int read = readFully(input, SKIP_BUF, 0, + (int) Math.min(numToSkip, SKIP_BUF_SIZE)); +if (read < 1) { break; } -remain -= n; +numToSkip -= read; } -return numToSkip - remain; +return available - numToSkip; } /**
[commons-compress] branch master updated: typos fix
This is an automated email from the ASF dual-hosted git repository. peterlee 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 f41756f typos fix f41756f is described below commit f41756f8024930384a60c5c57eb9eb2913ce1ae0 Author: PeterAlfredLee AuthorDate: Mon Jul 6 20:53:49 2020 +0800 typos fix --- src/changes/changes.xml | 2 +- .../apache/commons/compress/archivers/ar/ArArchiveInputStream.java| 2 +- .../org/apache/commons/compress/archivers/arj/ArjArchiveEntry.java| 2 +- .../apache/commons/compress/archivers/dump/DumpArchiveSummary.java| 4 ++-- .../java/org/apache/commons/compress/archivers/sevenz/CoderBase.java | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 377e2e6..b2b17d2 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -80,7 +80,7 @@ The type attribute can be add,update,fix,remove. ZipArchiveInputStream and ZipFile will now throw an IOException rather than a RuntimeException if the zip64 extra -field of an enty could not be parsed. +field of an entry could not be parsed. Improved detection of corrupt ZIP archives in ZipArchiveInputStream. diff --git a/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java index 1e367de..ca45d9e 100644 --- a/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java @@ -41,7 +41,7 @@ public class ArArchiveInputStream extends ArchiveInputStream { private boolean closed; /* - * If getNextEnxtry has been called, the entry metadata is stored in + * If getNextEntry has been called, the entry metadata is stored in * currentEntry. */ private ArArchiveEntry currentEntry = null; diff --git a/src/main/java/org/apache/commons/compress/archivers/arj/ArjArchiveEntry.java b/src/main/java/org/apache/commons/compress/archivers/arj/ArjArchiveEntry.java index 22d1f5d..947a751 100644 --- a/src/main/java/org/apache/commons/compress/archivers/arj/ArjArchiveEntry.java +++ b/src/main/java/org/apache/commons/compress/archivers/arj/ArjArchiveEntry.java @@ -87,7 +87,7 @@ public class ArjArchiveEntry implements ArchiveEntry { * machine in timezone UTC this method will return midnight * regardless of timezone if the archive has been created on a * non-Unix system and a time taking the current timezone into - * account if the archive has beeen created on Unix. + * account if the archive has been created on Unix. * * @return the last modified date */ diff --git a/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveSummary.java b/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveSummary.java index 55e7a78..47db7ff 100644 --- a/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveSummary.java +++ b/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveSummary.java @@ -278,8 +278,8 @@ public class DumpArchiveSummary { } /** - * Does this volume cotain extended attributes. - * @return true if volume cotains extended attributes. + * Does this volume contain extended attributes. + * @return true if volume contains extended attributes. */ public boolean isExtendedAttributes() { return (flags & 0x8000) == 0x8000; diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/CoderBase.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/CoderBase.java index e1f6086..d4ea715 100644 --- a/src/main/java/org/apache/commons/compress/archivers/sevenz/CoderBase.java +++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/CoderBase.java @@ -65,7 +65,7 @@ abstract class CoderBase { * @return a stream that reads from in using the configured coder and password. */ abstract InputStream decode(final String archiveName, -final InputStream in, long uncomressedLength, +final InputStream in, long uncompressedLength, final Coder coder, byte[] password, int maxMemoryLimitInKb) throws IOException; /**
[commons-compress] branch master updated: Add oss-fuzz to README.md
This is an automated email from the ASF dual-hosted git repository. peterlee 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 d4db6e5 Add oss-fuzz to README.md d4db6e5 is described below commit d4db6e5274a9b777ad1c2a8b96426a785baa3f02 Author: PeterAlfredLee AuthorDate: Thu Apr 22 23:10:57 2021 +0800 Add oss-fuzz to README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 14b83b3..89ca9b4 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ Apache Commons Compress [](https://coveralls.io/r/apache/commons-compress) [](https://maven-badges.herokuapp.com/maven-central/org.apache.commons/commons-compress/) [](https://javadoc.io/doc/org.apache.commons/commons-compress/1.20) +[](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:apache-commons) **Note: Commons Compress currently doesn't build on JDK 14+, we will address this before releasing Compress 1.21**.
[commons-compress] branch master updated: COMPRESS-565 : add a new option in Zip64Mode
This is an automated email from the ASF dual-hosted git repository. peterlee 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 f4b5586 COMPRESS-565 : add a new option in Zip64Mode f4b5586 is described below commit f4b5586835e56373d6099c44a8be58a77efe5db4 Author: PeterAlfredLee AuthorDate: Mon Feb 22 15:17:49 2021 +0800 COMPRESS-565 : add a new option in Zip64Mode Add a new AlwaysWithCompatibility in Zip64Mode, this is a compromise for some libraries including 7z and Expand-Archive Powershell utility(and likely Excel) And we will encode LFH Offset in the Zip64 Extended Information Extra Field if the Disk Number Start needs to be encoded, even through the LFH Offset itself doesn't need to be encoded. --- .../commons/compress/archivers/zip/Zip64Mode.java | 12 - .../archivers/zip/ZipArchiveOutputStream.java | 23 ++--- .../compress/archivers/zip/Zip64SupportIT.java | 56 ++ 3 files changed, 84 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/Zip64Mode.java b/src/main/java/org/apache/commons/compress/archivers/zip/Zip64Mode.java index d051e89..428b970 100644 --- a/src/main/java/org/apache/commons/compress/archivers/zip/Zip64Mode.java +++ b/src/main/java/org/apache/commons/compress/archivers/zip/Zip64Mode.java @@ -43,5 +43,15 @@ public enum Zip64Mode { * Use Zip64 extensions for all entries where they are required, * don't use them for entries that clearly don't require them. */ -AsNeeded +AsNeeded, +/** + * Always use Zip64 extensions for LFH and central directory as + * {@link Zip64Mode#Always} did, and at the meantime encode + * the relative offset of LFH and disk number start as needed in + * CFH as {@link Zip64Mode#AsNeeded} did. + * + * This is a compromise for some libraries including 7z and + * Expand-Archive Powershell utility(and likely Excel). + */ +AlwaysWithCompatibility } diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java index 5808bf5..f73af51 100644 --- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java @@ -749,7 +749,8 @@ public class ZipArchiveOutputStream extends ArchiveOutputStream { } private boolean isZip64Required(final ZipArchiveEntry entry1, final Zip64Mode requestedMode) { -return requestedMode == Zip64Mode.Always || isTooLargeForZip32(entry1); +return requestedMode == Zip64Mode.Always || requestedMode == Zip64Mode.AlwaysWithCompatibility +|| isTooLargeForZip32(entry1); } private boolean isTooLargeForZip32(final ZipArchiveEntry zipArchiveEntry){ @@ -940,6 +941,7 @@ public class ZipArchiveOutputStream extends ArchiveOutputStream { */ private boolean shouldAddZip64Extra(final ZipArchiveEntry entry, final Zip64Mode mode) { return mode == Zip64Mode.Always +|| mode == Zip64Mode.AlwaysWithCompatibility || entry.getSize() >= ZIP64_MAGIC || entry.getCompressedSize() >= ZIP64_MAGIC || (entry.getSize() == ArchiveEntry.SIZE_UNKNOWN @@ -1339,7 +1341,8 @@ public class ZipArchiveOutputStream extends ArchiveOutputStream { || ze.getSize() >= ZIP64_MAGIC || entryMetaData.offset >= ZIP64_MAGIC || ze.getDiskNumberStart() >= ZIP64_MAGIC_SHORT -|| zip64Mode == Zip64Mode.Always; +|| zip64Mode == Zip64Mode.Always +|| zip64Mode == Zip64Mode.AlwaysWithCompatibility; if (needsZip64Extra && zip64Mode == Zip64Mode.Never) { // must be the offset that is too big, otherwise an @@ -1418,7 +1421,8 @@ public class ZipArchiveOutputStream extends ArchiveOutputStream { putLong(ze.getCrc(), buf, CFH_CRC_OFFSET); if (ze.getCompressedSize() >= ZIP64_MAGIC || ze.getSize() >= ZIP64_MAGIC -|| zip64Mode == Zip64Mode.Always) { +|| zip64Mode == Zip64Mode.Always +|| zip64Mode == Zip64Mode.AlwaysWithCompatibility) { ZipLong.ZIP64_MAGIC.putLong(buf, CFH_COMPRESSED_SIZE_OFFSET); ZipLong.ZIP64_MAGIC.putLong(buf, CFH_ORIGINAL_SIZE_OFFSET); } else { @@ -1480,7 +1484,8 @@ public class ZipArchiveOutputStream extends ArchiveOutputStream { final Zip64ExtendedInformationExtraField z64 = getZip64Extra(ze); if (ze.getCompressedSize() >= ZIP64_MAGIC || ze.getSize() >= ZIP64_MAGIC
[commons-compress] branch master updated: document #169 and COMPRESS-565
This is an automated email from the ASF dual-hosted git repository. peterlee 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 b5a9e88 document #169 and COMPRESS-565 b5a9e88 is described below commit b5a9e88cb6b03f9665ff67740aa09db6e53b7bcf Author: PeterAlfredLee AuthorDate: Wed May 19 15:58:34 2021 +0800 document #169 and COMPRESS-565 --- src/changes/changes.xml | 11 +++ 1 file changed, 11 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 72c22b6..dd85b43 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -341,6 +341,17 @@ The type attribute can be add,update,fix,remove. Update org.tukaani:xz from 1.8 to 1.9 + +Add a new AlwaysWithCompatibility in Zip64Mode, this is a +compromise for some libraries including 7z and Expand-Archive +Powershell utility(and likely Excel). + +And we will encode both the LFH offset and Disk Number Start +in the ZIP64 Extended Information Extra Field - even if only +the disk number needs to be encoded. + +Github Pull Request #169. +
[commons-compress] branch master updated: fix build failure
This is an automated email from the ASF dual-hosted git repository. peterlee 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 03fba28 fix build failure 03fba28 is described below commit 03fba28c52f1c1f40960200515c5f915b7c1cec4 Author: PeterAlfredLee AuthorDate: Wed May 19 16:01:21 2021 +0800 fix build failure --- .../java/org/apache/commons/compress/archivers/zip/Zip64SupportIT.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportIT.java b/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportIT.java index 07c85c7..68a4968 100644 --- a/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportIT.java +++ b/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportIT.java @@ -30,6 +30,8 @@ import static org.junit.Assume.assumeTrue; import java.io.BufferedOutputStream; import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.RandomAccessFile;
[commons-compress] branch master updated: COMPRESS-583: update the changelog of COMPRESS-404
This is an automated email from the ASF dual-hosted git repository. peterlee 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 7bc8679 COMPRESS-583: update the changelog of COMPRESS-404 7bc8679 is described below commit 7bc86793d2533ef314550efe2b79df752abdc8d4 Author: PeterAlfredLee AuthorDate: Sat Jul 31 09:38:52 2021 +0800 COMPRESS-583: update the changelog of COMPRESS-404 --- src/changes/changes.xml | 4 1 file changed, 4 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 24b28c5..ee52465 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -149,6 +149,10 @@ you relied on the recovery attempt."> Update the class of variable file in TarArchiveEntry from java.io.File to java.nio.file.Path. Corresponding constructors and methods are also modified/added. + +NOTE: The UserID and GroupID will also be read if they are +available. The previous default value UserID:GroupdID of was 0:0. +This may cause a reproducibility problem. Github Pull Request #97.
[commons-compress] branch master updated: COMPRESS-583: document more datails
This is an automated email from the ASF dual-hosted git repository. peterlee 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 d57b8e9 COMPRESS-583: document more datails d57b8e9 is described below commit d57b8e9068bc0184b783aa488e613f4fcf2140d6 Author: PeterAlfredLee AuthorDate: Sat Jul 31 09:59:14 2021 +0800 COMPRESS-583: document more datails --- src/changes/changes.xml | 9 ++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index ee52465..e38e27c 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -150,9 +150,12 @@ you relied on the recovery attempt."> java.io.File to java.nio.file.Path. Corresponding constructors and methods are also modified/added. -NOTE: The UserID and GroupID will also be read if they are -available. The previous default value UserID:GroupdID of was 0:0. -This may cause a reproducibility problem. +NOTE: The userName, groupName, userID and groupID will also be +set if they are available. The userName and groupName was not +set previously, and the previous value of UserID:GroupID was +0:0 by default. +Please note this may cause a reproducibility problem. + Github Pull Request #97.
[commons-compress] branch master updated: fix COMPRESS-596
This is an automated email from the ASF dual-hosted git repository. peterlee 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 c8a14ef fix COMPRESS-596 c8a14ef is described below commit c8a14ef085a21b276233d4bab09d0d044b01e15d Author: PeterAlfredLee AuthorDate: Tue Dec 7 12:09:35 2021 +0800 fix COMPRESS-596 --- src/changes/changes.xml| 4 src/site/xdoc/examples.xml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index e1bc453..5bb14ae 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -96,6 +96,10 @@ The type attribute can be add,update,fix,remove. Bump commons.japicmp.version from 0.15.3 to 0.15.4. + +Fix minor problem in examples. +
[commons-compress] branch master updated: COMPRESS-603
This is an automated email from the ASF dual-hosted git repository. peterlee 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 510be7f COMPRESS-603 510be7f is described below commit 510be7f741c725d2293c77fb64513540b9195218 Author: PeterAlfredLee AuthorDate: Wed Feb 9 15:44:19 2022 +0800 COMPRESS-603 Expander should be able to work if an entry's name is "./". --- src/changes/changes.xml| 3 ++ .../compress/archivers/examples/Expander.java | 5 +++- .../compress/archivers/examples/ExpanderTest.java | 35 ++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index ddf1e48..0d17514 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -113,6 +113,9 @@ The type attribute can be add,update,fix,remove. Bump slf4j-api from 1.7.30 to 1.7.35 #213, #241. + +Expander should be able to work if an entry's name is "./". +
[commons-compress] branch master updated (b70af20 -> 7c17493)
This is an automated email from the ASF dual-hosted git repository. peterlee pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git. from b70af20 GitHub actions/setup-java@v1 -> actions/setup-java@v1.4.0. add 7c17493 set fail-fast as false for GH actions No new revisions were added by this update. Summary of changes: .github/workflows/maven.yml | 1 + 1 file changed, 1 insertion(+)
[commons-compress] branch master updated: COMPRESS-543 : fix for test fails on Windows
This is an automated email from the ASF dual-hosted git repository. peterlee 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 0b9dbbc COMPRESS-543 : fix for test fails on Windows 0b9dbbc is described below commit 0b9dbbcee3d4dd35e92ccad1c55d5f429c072ae4 Author: PeterAlfredLee AuthorDate: Mon Aug 10 20:34:51 2020 +0800 COMPRESS-543 : fix for test fails on Windows --- src/changes/changes.xml | 4 .../compress/archivers/zip/UTF8ZipFilesTest.java| 17 +++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 42d14ea..bb1dc9a 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -169,6 +169,10 @@ The type attribute can be add,update,fix,remove. Update GitHub actions/checkout from v1 to v2.3.1 #114. + +Fix for test fails on Windows. The tests are failing because the +default charset is not UTF-8. + diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java index d1ac599..7c0b88b 100644 --- a/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java @@ -26,6 +26,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; +import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.Enumeration; import java.util.zip.CRC32; @@ -135,7 +136,13 @@ public class UTF8ZipFilesTest extends AbstractTestCase { final File archive = getFile("utf8-winzip-test.zip"); ZipFile zf = null; try { -zf = new ZipFile(archive, null, true); +// fix for test fails on Windows with default charset that is not UTF-8 +String encoding = null; +if (Charset.defaultCharset() != StandardCharsets.UTF_8) { +encoding = StandardCharsets.UTF_8.name(); +} + +zf = new ZipFile(archive, encoding, true); assertCanRead(zf, ASCII_TXT); assertCanRead(zf, EURO_FOR_DOLLAR_TXT); assertCanRead(zf, OIL_BARREL_TXT); @@ -162,7 +169,13 @@ public class UTF8ZipFilesTest extends AbstractTestCase { new FileInputStream(getFile("utf8-winzip-test.zip")); ZipArchiveInputStream zi = null; try { -zi = new ZipArchiveInputStream(archive, null, true); +// fix for test fails on Windows with default charset that is not UTF-8 +String encoding = null; +if (Charset.defaultCharset() != StandardCharsets.UTF_8) { +encoding = StandardCharsets.UTF_8.name(); +} + +zi = new ZipArchiveInputStream(archive, encoding, true); assertEquals(EURO_FOR_DOLLAR_TXT, zi.getNextEntry().getName()); assertEquals(OIL_BARREL_TXT, zi.getNextEntry().getName()); assertEquals(ASCII_TXT, zi.getNextEntry().getName());
[commons-compress] branch master updated: COMPRESS-544 : truncated tar detect
This is an automated email from the ASF dual-hosted git repository. peterlee 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 b927280 COMPRESS-544 : truncated tar detect b927280 is described below commit b92728060ae6b82904d7d1453b05223f2917fc73 Author: PeterAlfredLee AuthorDate: Thu Aug 13 16:30:55 2020 +0800 COMPRESS-544 : truncated tar detect TarArchiveInputStream can not detect truncated tar archive when skipping bytes. This is a fix for it. --- src/changes/changes.xml| 4 ++ .../archivers/tar/TarArchiveInputStream.java | 50 ++--- .../archivers/tar/TarArchiveInputStreamTest.java | 18 .../COMPRESS-544_truncated_in_content.tar | Bin 0 -> 2067 bytes .../COMPRESS-544_truncated_in_padding.tar | Bin 0 -> 2076 bytes 5 files changed, 65 insertions(+), 7 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 934573d..4301093 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -173,6 +173,10 @@ The type attribute can be add,update,fix,remove. Fix for test fails on Windows. The tests are failing because the default charset is not UTF-8. + +TarArchiveInputStream can not detect a truncated tar in skip() +and skipRecordPadding(). + diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java index 5c08ba0..3b99366 100644 --- a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java @@ -24,6 +24,7 @@ package org.apache.commons.compress.archivers.tar; import java.io.ByteArrayOutputStream; +import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; @@ -261,8 +262,8 @@ public class TarArchiveInputStream extends ArchiveInputStream { * @param n *the number of bytes to be skipped. * @return the actual number of bytes skipped. - * @throws IOException - *if some other I/O error occurs. + * @throws IOException if a truncated tar archive is detected + * or some other I/O error occurs */ @Override public long skip(final long n) throws IOException { @@ -270,13 +271,19 @@ public class TarArchiveInputStream extends ArchiveInputStream { return 0; } +final long availableOfInputStream = inputStream.available(); final long available = currEntry.getRealSize() - entryOffset; -final long skipped; +final long numToSkip = Math.min(n, available); +long skipped; + if (!currEntry.isSparse()) { -skipped = IOUtils.skip(inputStream, Math.min(n, available)); +skipped = IOUtils.skip(inputStream, numToSkip); } else { -skipped = skipSparse(Math.min(n, available)); +skipped = skipSparse(numToSkip); } + +skipped = getActuallySkipped(availableOfInputStream, skipped, numToSkip); + count(skipped); entryOffset += skipped; return skipped; @@ -436,18 +443,47 @@ public class TarArchiveInputStream extends ArchiveInputStream { /** * The last record block should be written at the full size, so skip any - * additional space used to fill a record after an entry + * additional space used to fill a record after an entry. + * + * @throws IOException if a truncated tar archive is detected */ private void skipRecordPadding() throws IOException { if (!isDirectory() && this.entrySize > 0 && this.entrySize % this.recordSize != 0) { +final long available = inputStream.available(); final long numRecords = (this.entrySize / this.recordSize) + 1; final long padding = (numRecords * this.recordSize) - this.entrySize; -final long skipped = IOUtils.skip(inputStream, padding); +long skipped = IOUtils.skip(inputStream, padding); + +skipped = getActuallySkipped(available, skipped, padding); + count(skipped); } } /** + * For FileInputStream, the skip always return the number you input, so we + * need the available bytes to determine how many bytes are actually skipped + * + * @param available available bytes returned by inputStream.available() + * @param skipped skipped bytes returned by inputStream.skip() + * @param expected bytes expected to skip + * @return number of bytes actually skipped + * @throws IOException if a truncate
[commons-compress] branch master updated: COMPRESS-544 : minor bug fix
This is an automated email from the ASF dual-hosted git repository. peterlee 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 870b54c COMPRESS-544 : minor bug fix 870b54c is described below commit 870b54cd922cbeb73d945a24d4a5d6df49672ca8 Author: PeterAlfredLee AuthorDate: Fri Aug 14 11:30:46 2020 +0800 COMPRESS-544 : minor bug fix --- .../apache/commons/compress/archivers/tar/TarArchiveInputStream.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java index 3b99366..17275de 100644 --- a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java @@ -278,11 +278,13 @@ public class TarArchiveInputStream extends ArchiveInputStream { if (!currEntry.isSparse()) { skipped = IOUtils.skip(inputStream, numToSkip); +// for non-sparse entry, we should get the bytes actually skipped bytes along with +// inputStream.available() if inputStream is instance of FileInputStream +skipped = getActuallySkipped(availableOfInputStream, skipped, numToSkip); } else { skipped = skipSparse(numToSkip); } -skipped = getActuallySkipped(availableOfInputStream, skipped, numToSkip); count(skipped); entryOffset += skipped;
[commons-compress] branch master updated (870b54c -> 464ba19)
This is an automated email from the ASF dual-hosted git repository. peterlee pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git. from 870b54c COMPRESS-544 : minor bug fix new 80e5a46 COMPRESS-542: Lazy allocation of SevenZArchiveEntry to prevent OOM on corrupt files new 41359f5 COMPRESS-542: Prevent OOM at array creation new 464ba19 Merge pull request #120 from theobisproject/COMPRESS-542 The 3009 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference. Summary of changes: .../compress/archivers/sevenz/SevenZFile.java | 109 + .../compress/archivers/sevenz/SevenZFileTest.java | 19 src/test/resources/COMPRESS-542-1.7z | Bin 0 -> 102 bytes src/test/resources/COMPRESS-542-2.7z | Bin 0 -> 165 bytes .../resources/COMPRESS-542-endheadercorrupted.7z | Bin 0 -> 233 bytes .../resources/COMPRESS-542-endheadercorrupted2.7z | Bin 0 -> 233 bytes 6 files changed, 87 insertions(+), 41 deletions(-) create mode 100644 src/test/resources/COMPRESS-542-1.7z create mode 100644 src/test/resources/COMPRESS-542-2.7z create mode 100644 src/test/resources/COMPRESS-542-endheadercorrupted.7z create mode 100644 src/test/resources/COMPRESS-542-endheadercorrupted2.7z
[commons-compress] branch master updated: COMPRESS-542 : record change
This is an automated email from the ASF dual-hosted git repository. peterlee 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 5fc625d COMPRESS-542 : record change 5fc625d is described below commit 5fc625d91c883f3e7c99f9e27ab78ffdbb3f5ae9 Author: PeterAlfredLee AuthorDate: Sat Aug 15 11:36:44 2020 +0800 COMPRESS-542 : record change Record change for Compress-542 with PR#120 --- src/changes/changes.xml | 12 ++-- .../apache/commons/compress/archivers/sevenz/SevenZFile.java | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 4301093..ad224f7 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -169,14 +169,22 @@ The type attribute can be add,update,fix,remove. Update GitHub actions/checkout from v1 to v2.3.1 #114, #124. - + Fix for test fails on Windows. The tests are failing because the default charset is not UTF-8. - + TarArchiveInputStream can not detect a truncated tar in skip() and skipRecordPadding(). + +Make the memory allocation in SevenZFile.readFilesInfo a lazy +allocation to avoid OOM when dealing some giant 7z archives. +Github Pull Request #120. + diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java index aacf34a..bbbca55 100644 --- a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java +++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java @@ -976,7 +976,7 @@ public class SevenZFile implements Closeable { throw new IOException("File names length invalid"); } assertFitsIntoInt("file names length", size - 1); -final byte[] names = new byte[(int)(size - 1)]; +final byte[] names = new byte[(int) (size - 1)]; header.get(names); int nextFile = 0; int nextName = 0;
[commons-compress] branch master updated: COMPRESS-546 : throw exception on corrputed z64
This is an automated email from the ASF dual-hosted git repository. peterlee 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 20f2dfb COMPRESS-546 : throw exception on corrputed z64 20f2dfb is described below commit 20f2dfbc48a18d8cce8f95005d067752c0bef31f Author: PeterAlfredLee AuthorDate: Sat Aug 15 17:55:58 2020 +0800 COMPRESS-546 : throw exception on corrputed z64 ZipArchiveInputStream should throw exception if a corrputed zip64 extra field is met. --- src/changes/changes.xml| 5 + .../compress/archivers/zip/ZipArchiveInputStream.java | 5 + .../compress/archivers/zip/ZipArchiveInputStreamTest.java | 9 + src/test/resources/COMPRESS-546.zip| Bin 0 -> 77 bytes 4 files changed, 19 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index ad224f7..73cf48c 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -185,6 +185,11 @@ The type attribute can be add,update,fix,remove. allocation to avoid OOM when dealing some giant 7z archives. Github Pull Request #120. + +ZipArchiveInputStream should throw an exception if a corrputed +zip64 extra field is met. + diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java index a0ace8d..66fd17b 100644 --- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java @@ -429,6 +429,11 @@ public class ZipArchiveInputStream extends ArchiveInputStream implements InputSt if (!current.hasDataDescriptor) { if (z64 != null // same as current.usesZip64 but avoids NPE warning && (ZipLong.ZIP64_MAGIC.equals(cSize) || ZipLong.ZIP64_MAGIC.equals(size)) ) { +if (z64.getCompressedSize() == null || z64.getSize() == null) { +// avoid NPE if it's a corrupted zip archive +throw new ZipException("archive contains corrupted zip64 extra field"); +} + current.entry.setCompressedSize(z64.getCompressedSize().getLongValue()); current.entry.setSize(z64.getSize().getLongValue()); } else if (cSize != null && size != null) { diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java index 9e47fcd..23b695a 100644 --- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java @@ -710,6 +710,15 @@ public class ZipArchiveInputStreamTest { }); } +@Test(expected = IOException.class) +public void throwsIOExceptionIfThereIsCorruptedZip64Extra() throws IOException { +try (InputStream fis = new FileInputStream(getFile("COMPRESS-546.zip")); + ZipArchiveInputStream zipInputStream = new ZipArchiveInputStream(fis);) { +while (zipInputStream.getNextZipEntry() != null) { +} +} +} + private static byte[] readEntry(final ZipArchiveInputStream zip, final ZipArchiveEntry zae) throws IOException { final int len = (int)zae.getSize(); final byte[] buff = new byte[len]; diff --git a/src/test/resources/COMPRESS-546.zip b/src/test/resources/COMPRESS-546.zip new file mode 100644 index 000..0fad172 Binary files /dev/null and b/src/test/resources/COMPRESS-546.zip differ
[commons-compress] branch master updated: fix for signature detect
This is an automated email from the ASF dual-hosted git repository. peterlee 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 86bb35a fix for signature detect 86bb35a is described below commit 86bb35aa4e92da6c3c9e78551dffc3fb0193caab Author: PeterAlfredLee AuthorDate: Mon Aug 17 17:14:17 2020 +0800 fix for signature detect fix for problems in signature detecting of Central Directory File Signature --- .../apache/commons/compress/archivers/zip/ZipArchiveInputStream.java| 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java index 66fd17b..32bb562 100644 --- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java @@ -990,7 +990,7 @@ public class ZipArchiveInputStream extends ArchiveInputStream implements InputSt int expectDDPos = i; if (i >= expectedDDLen && (buf.array()[i + 2] == LFH[2] && buf.array()[i + 3] == LFH[3]) -|| (buf.array()[i] == CFH[2] && buf.array()[i + 3] == CFH[3])) { +|| (buf.array()[i + 2] == CFH[2] && buf.array()[i + 3] == CFH[3])) { // found a LFH or CFH: expectDDPos = i - expectedDDLen; done = true;
[commons-compress] branch master updated (aba9018 -> ce59f39)
This is an automated email from the ASF dual-hosted git repository. peterlee pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git. from aba9018 Refactor some duplication. add ce59f39 fix javadoc error on java 11 No new revisions were added by this update. Summary of changes: pom.xml | 16 1 file changed, 8 insertions(+), 8 deletions(-)
[commons-compress] branch master updated: COMPRESS-548 : throw exception if length of zip extra field is too short
This is an automated email from the ASF dual-hosted git repository. peterlee 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 08d754c COMPRESS-548 : throw exception if length of zip extra field is too short 08d754c is described below commit 08d754cce4bb9a3bc30467e965ab86c64473e032 Author: PeterAlfredLee AuthorDate: Mon Aug 24 16:58:01 2020 +0800 COMPRESS-548 : throw exception if length of zip extra field is too short --- src/changes/changes.xml| 5 + .../commons/compress/archivers/zip/AsiExtraField.java | 4 .../compress/archivers/zip/ZipArchiveInputStreamTest.java | 9 + src/test/resources/COMPRESS-548.zip| Bin 0 -> 79 bytes 4 files changed, 18 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index b217d77..3a3731d 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -212,6 +212,11 @@ The type attribute can be add,update,fix,remove. Add a new maven profile in pom.xml for JDK14+ to ignore the failing tests about Pack200. + +Throw an exception when reading the zip extra field if the +length is too short. + diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/AsiExtraField.java b/src/main/java/org/apache/commons/compress/archivers/zip/AsiExtraField.java index d2ed167..1909a2f 100644 --- a/src/main/java/org/apache/commons/compress/archivers/zip/AsiExtraField.java +++ b/src/main/java/org/apache/commons/compress/archivers/zip/AsiExtraField.java @@ -266,6 +266,10 @@ public class AsiExtraField implements ZipExtraField, UnixStat, Cloneable { @Override public void parseFromLocalFileData(final byte[] data, final int offset, final int length) throws ZipException { +if (length < WORD) { +throw new ZipException("The length is too short, only " ++ length + " bytes, expected at least " + WORD); +} final long givenChecksum = ZipLong.getValue(data, offset); final byte[] tmp = new byte[length - WORD]; diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java index 23b695a..9175476 100644 --- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java @@ -719,6 +719,15 @@ public class ZipArchiveInputStreamTest { } } +@Test +public void testZipWithBadExtraFields() throws IOException { +try (InputStream fis = new FileInputStream(getFile("COMPRESS-548.zip")); + ZipArchiveInputStream zipInputStream = new ZipArchiveInputStream(fis);) { +while (zipInputStream.getNextZipEntry() != null) { +} +} +} + private static byte[] readEntry(final ZipArchiveInputStream zip, final ZipArchiveEntry zae) throws IOException { final int len = (int)zae.getSize(); final byte[] buff = new byte[len]; diff --git a/src/test/resources/COMPRESS-548.zip b/src/test/resources/COMPRESS-548.zip new file mode 100644 index 000..2795cd2 Binary files /dev/null and b/src/test/resources/COMPRESS-548.zip differ
[commons-compress] branch master updated: COMPRESS-548 : throw exception if length of zip extra field is too short
This is an automated email from the ASF dual-hosted git repository. peterlee 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 08d754c COMPRESS-548 : throw exception if length of zip extra field is too short 08d754c is described below commit 08d754cce4bb9a3bc30467e965ab86c64473e032 Author: PeterAlfredLee AuthorDate: Mon Aug 24 16:58:01 2020 +0800 COMPRESS-548 : throw exception if length of zip extra field is too short --- src/changes/changes.xml| 5 + .../commons/compress/archivers/zip/AsiExtraField.java | 4 .../compress/archivers/zip/ZipArchiveInputStreamTest.java | 9 + src/test/resources/COMPRESS-548.zip| Bin 0 -> 79 bytes 4 files changed, 18 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index b217d77..3a3731d 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -212,6 +212,11 @@ The type attribute can be add,update,fix,remove. Add a new maven profile in pom.xml for JDK14+ to ignore the failing tests about Pack200. + +Throw an exception when reading the zip extra field if the +length is too short. + diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/AsiExtraField.java b/src/main/java/org/apache/commons/compress/archivers/zip/AsiExtraField.java index d2ed167..1909a2f 100644 --- a/src/main/java/org/apache/commons/compress/archivers/zip/AsiExtraField.java +++ b/src/main/java/org/apache/commons/compress/archivers/zip/AsiExtraField.java @@ -266,6 +266,10 @@ public class AsiExtraField implements ZipExtraField, UnixStat, Cloneable { @Override public void parseFromLocalFileData(final byte[] data, final int offset, final int length) throws ZipException { +if (length < WORD) { +throw new ZipException("The length is too short, only " ++ length + " bytes, expected at least " + WORD); +} final long givenChecksum = ZipLong.getValue(data, offset); final byte[] tmp = new byte[length - WORD]; diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java index 23b695a..9175476 100644 --- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java @@ -719,6 +719,15 @@ public class ZipArchiveInputStreamTest { } } +@Test +public void testZipWithBadExtraFields() throws IOException { +try (InputStream fis = new FileInputStream(getFile("COMPRESS-548.zip")); + ZipArchiveInputStream zipInputStream = new ZipArchiveInputStream(fis);) { +while (zipInputStream.getNextZipEntry() != null) { +} +} +} + private static byte[] readEntry(final ZipArchiveInputStream zip, final ZipArchiveEntry zae) throws IOException { final int len = (int)zae.getSize(); final byte[] buff = new byte[len]; diff --git a/src/test/resources/COMPRESS-548.zip b/src/test/resources/COMPRESS-548.zip new file mode 100644 index 000..2795cd2 Binary files /dev/null and b/src/test/resources/COMPRESS-548.zip differ
[commons-compress] branch master updated: COMPRESS-554 : throw IOExcepiton if error is met
This is an automated email from the ASF dual-hosted git repository. peterlee 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 319a848 COMPRESS-554 : throw IOExcepiton if error is met 319a848 is described below commit 319a848ce71953ace6977f9b2dc505f24576addc Author: PeterAlfredLee AuthorDate: Tue Sep 1 15:16:53 2020 +0800 COMPRESS-554 : throw IOExcepiton if error is met Throw an decleared IOException if a null entry is met when reading a global pax header instead of a runtime NPE. --- src/changes/changes.xml | 7 ++- .../compress/archivers/tar/TarArchiveInputStream.java | 4 .../archivers/tar/TarArchiveInputStreamTest.java| 9 + src/test/resources/COMPRESS-554.tar | Bin 0 -> 10842 bytes 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 3a3731d..c10d9d7 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -214,9 +214,14 @@ The type attribute can be add,update,fix,remove. -Throw an exception when reading the zip extra field if the +Throw an IOException when reading the zip extra field if the length is too short. + +Throw an decleared IOException if a null entry is met when +reading a global pax header instead of a runtime NPE. + diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java index 42aed57..62766f2 100644 --- a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java @@ -573,6 +573,10 @@ public class TarArchiveInputStream extends ArchiveInputStream { private void readGlobalPaxHeaders() throws IOException { globalPaxHeaders = parsePaxHeaders(this, globalSparseHeaders); getNextEntry(); // Get the actual file entry + +if (currEntry == null) { +throw new IOException("Error detected parsing the pax header"); +} } /** diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java index 924542f..17f4728 100644 --- a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java @@ -460,6 +460,15 @@ public class TarArchiveInputStreamTest extends AbstractTestCase { } } +@Test(expected = IOException.class) +public void stCompress554() throws IOException { +try (FileInputStream in = new FileInputStream(getFile("./COMPRESS-554.tar")); + TarArchiveInputStream archive = new TarArchiveInputStream(in)) { +while (archive.getNextTarEntry() != null) { +} +} +} + private TarArchiveInputStream getTestStream(final String name) { return new TarArchiveInputStream( TarArchiveInputStreamTest.class.getResourceAsStream(name)); diff --git a/src/test/resources/COMPRESS-554.tar b/src/test/resources/COMPRESS-554.tar new file mode 100644 index 000..71a6173 Binary files /dev/null and b/src/test/resources/COMPRESS-554.tar differ
[commons-compress] branch master updated: COMPRESS-554 : update name of testcase
This is an automated email from the ASF dual-hosted git repository. peterlee 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 3b28227 COMPRESS-554 : update name of testcase 3b28227 is described below commit 3b28227a5ebed06f15e5706a4d5801c46549d72c Author: PeterAlfredLee AuthorDate: Tue Sep 1 16:19:41 2020 +0800 COMPRESS-554 : update name of testcase --- .../commons/compress/archivers/tar/TarArchiveInputStreamTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java index 17f4728..d7b5396 100644 --- a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java @@ -461,7 +461,7 @@ public class TarArchiveInputStreamTest extends AbstractTestCase { } @Test(expected = IOException.class) -public void stCompress554() throws IOException { +public void testThrowExceptionWithNullEntry() throws IOException { try (FileInputStream in = new FileInputStream(getFile("./COMPRESS-554.tar")); TarArchiveInputStream archive = new TarArchiveInputStream(in)) { while (archive.getNextTarEntry() != null) {
[commons-compress] branch master updated: COMPRESS-547 : add asserts for Arrays.copyOf
This is an automated email from the ASF dual-hosted git repository. peterlee 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 4eb3bbe COMPRESS-547 : add asserts for Arrays.copyOf 4eb3bbe is described below commit 4eb3bbe8e95f5e3b6388b1e8db28b862cc712294 Author: PeterAlfredLee AuthorDate: Wed Sep 2 20:54:46 2020 +0800 COMPRESS-547 : add asserts for Arrays.copyOf Add asserts for Arrays.copyOf in X0017_StrongEncryptionHeader. --- src/changes/changes.xml | 4 .../commons/compress/archivers/zip/X0017_StrongEncryptionHeader.java | 4 2 files changed, 8 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index c10d9d7..2fdb039 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -222,6 +222,10 @@ The type attribute can be add,update,fix,remove. Throw an decleared IOException if a null entry is met when reading a global pax header instead of a runtime NPE. + +Add asserts for Arrays.copyOf in X0017_StrongEncryptionHeader. + diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/X0017_StrongEncryptionHeader.java b/src/main/java/org/apache/commons/compress/archivers/zip/X0017_StrongEncryptionHeader.java index 9e27771..e1a5ebe 100644 --- a/src/main/java/org/apache/commons/compress/archivers/zip/X0017_StrongEncryptionHeader.java +++ b/src/main/java/org/apache/commons/compress/archivers/zip/X0017_StrongEncryptionHeader.java @@ -341,6 +341,7 @@ public class X0017_StrongEncryptionHeader extends PKWareExtraHeader { assertMinimalLength(4, length); final int ivSize = ZipShort.getValue(data, offset); assertDynamicLengthFits("ivSize", ivSize, 4, length); +assertMinimalLength(offset + 4, ivSize); // TODO: what is at offset + 2? this.ivData = Arrays.copyOfRange(data, offset + 4, ivSize); @@ -353,6 +354,7 @@ public class X0017_StrongEncryptionHeader extends PKWareExtraHeader { final int erdSize = ZipShort.getValue(data, offset + ivSize + 14); assertDynamicLengthFits("erdSize", erdSize, ivSize + 16, length); +assertMinimalLength(offset + ivSize + 16, erdSize); this.erdData = Arrays.copyOfRange(data, offset + ivSize + 16, erdSize); assertMinimalLength(16 + 4 + ivSize + erdSize, length); @@ -365,7 +367,9 @@ public class X0017_StrongEncryptionHeader extends PKWareExtraHeader { throw new ZipException("Invalid X0017_StrongEncryptionHeader: vSize " + vSize + " is too small to hold CRC"); } +assertMinimalLength(offset + ivSize + 22 + erdSize, vSize - 4); this.vData = Arrays.copyOfRange(data, offset + ivSize + 22 + erdSize, vSize - 4); +assertMinimalLength(offset + ivSize + 22 + erdSize + vSize - 4, 4); this.vCRC32 = Arrays.copyOfRange(data, offset + ivSize + 22 + erdSize + vSize - 4, 4); } else { assertMinimalLength(ivSize + 20 + erdSize + 6, length); // up to and including resize
[commons-compress] branch master updated: COMPRESS-550 : add writePreamble to ZipArchiveInputStream
This is an automated email from the ASF dual-hosted git repository. peterlee 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 a40c53d COMPRESS-550 : add writePreamble to ZipArchiveInputStream a40c53d is described below commit a40c53d1494d71d09f57880f1a333445ddf4c535 Author: PeterAlfredLee AuthorDate: Tue Aug 18 15:22:39 2020 +0800 COMPRESS-550 : add writePreamble to ZipArchiveInputStream Add writePreamble to ZipArchiveInputStream. This is used to create self-extracting zips. --- .../archivers/zip/ZipArchiveOutputStream.java | 29 .../compress/archivers/zip/ZipFileTest.java| 80 ++ 2 files changed, 109 insertions(+) diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java index e145e6d..3d63bf2 100644 --- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java @@ -1005,6 +1005,35 @@ public class ZipArchiveOutputStream extends ArchiveOutputStream { } /** + * Write preamble data. For most of time, this is used to + * make self-extracting zips. + * + * @param preamble data to write + * @throws IOException if an entry already exists + * @since 1.21 + */ +public void writePreamble(final byte[] preamble) throws IOException { +writePreamble(preamble, 0, preamble.length); +} + +/** + * Write preamble data. For most of time, this is used to + * make self-extracting zips. + * + * @param preamble data to write + * @param offset the start offset in the data + * @param length the number of bytes to write + * @throws IOException if an entry already exists + * @since 1.21 + */ +public void writePreamble(final byte[] preamble, final int offset, final int length) throws IOException { +if (entry != null) { +throw new IllegalStateException("Preamble must be written before creating an entry"); +} +this.streamCompressor.writeCounted(preamble, offset, length); +} + +/** * Writes bytes to ZIP entry. * @param b the byte array to write * @param offset the start position to write from diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java index c2b6485..1d43752 100644 --- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java @@ -763,6 +763,86 @@ public class ZipFileTest { outputStream.setLevel(Deflater.BEST_COMPRESSION + 1); } +@Test(expected = IllegalStateException.class) +public void throwsExceptionWhenWritingPreamble() throws IOException { +final ZipArchiveOutputStream outputStream = new ZipArchiveOutputStream(new ByteArrayOutputStream()); +outputStream.putArchiveEntry(new ZipArchiveEntry()); +outputStream.writePreamble(new byte[0]); +} + +@Test +public void testSelfExtractingZipUsingUnzipsfx() throws IOException, InterruptedException { +final File unzipsfx = new File("/usr/bin/unzipsfx"); +if (!unzipsfx.exists()) { +return; +} + +final File testZip = File.createTempFile("commons-compress-selfExtractZipTest", ".zip"); +testZip.deleteOnExit(); + +final String testEntryName = "test_self_extract_zip/foo"; +final File extractedFile = new File(testZip.getParentFile(), testEntryName); +extractedFile.deleteOnExit(); + +OutputStream outputStream = null; +InputStream inputStream = null; +final byte[] testData = new byte[]{1, 2, 3, 4}; +byte[] buffer = new byte[512]; +int bytesRead; +try (InputStream unzipsfxInputStream = new FileInputStream(unzipsfx)) { +outputStream = new FileOutputStream(testZip); +final ZipArchiveOutputStream zo = new ZipArchiveOutputStream(outputStream); + +while ((bytesRead = unzipsfxInputStream.read(buffer)) > 0) { +zo.writePreamble(buffer, 0, bytesRead); +} + +ZipArchiveEntry ze = new ZipArchiveEntry(testEntryName); +ze.setMethod(ZipEntry.STORED); +ze.setSize(4); +ze.setCrc(0xb63cfbcdl); +zo.putArchiveEntry(ze); +zo.write(testData); +zo.closeArchiveEntry(); +zo.close(); +outputStream.close(); +outputStream = null; + +final ProcessBuilder pbChmod
[commons-compress] branch master updated: COMPRESS-550 : document in changes
This is an automated email from the ASF dual-hosted git repository. peterlee 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 b0d590d COMPRESS-550 : document in changes b0d590d is described below commit b0d590d65b277bb92a0270529de5ac7d69b443ab Author: PeterAlfredLee AuthorDate: Mon Sep 7 14:40:26 2020 +0800 COMPRESS-550 : document in changes --- src/changes/changes.xml | 9 + 1 file changed, 9 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 2fdb039..a7b743e 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -226,6 +226,15 @@ The type attribute can be add,update,fix,remove. due-to="Maksim Zuev" dev="PeterLee"> Add asserts for Arrays.copyOf in X0017_StrongEncryptionHeader. + +Add writePreamble to ZipArchiveInputStream. This method could +write raw data to zip archive before any entry was written to +the zip archive. +For most of the time, this is used to create self-extracting +zip. +Github Pull Request #127. +
[commons-compress] branch master updated: COMPRESS-550 : document in changes
This is an automated email from the ASF dual-hosted git repository. peterlee 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 b0d590d COMPRESS-550 : document in changes b0d590d is described below commit b0d590d65b277bb92a0270529de5ac7d69b443ab Author: PeterAlfredLee AuthorDate: Mon Sep 7 14:40:26 2020 +0800 COMPRESS-550 : document in changes --- src/changes/changes.xml | 9 + 1 file changed, 9 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 2fdb039..a7b743e 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -226,6 +226,15 @@ The type attribute can be add,update,fix,remove. due-to="Maksim Zuev" dev="PeterLee"> Add asserts for Arrays.copyOf in X0017_StrongEncryptionHeader. + +Add writePreamble to ZipArchiveInputStream. This method could +write raw data to zip archive before any entry was written to +the zip archive. +For most of the time, this is used to create self-extracting +zip. +Github Pull Request #127. +
[commons-compress] branch master updated: Fix for CFH detect in ZipArchiveInputStream
This is an automated email from the ASF dual-hosted git repository. peterlee 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 8a65cc9 Fix for CFH detect in ZipArchiveInputStream 8a65cc9 is described below commit 8a65cc9f7db7a851af562c7d098bb06283b64a85 Author: PeterAlfredLee AuthorDate: Thu Sep 24 14:25:55 2020 +0800 Fix for CFH detect in ZipArchiveInputStream The problem has been fixed in commit 86bb35a. This commit just add a test for it, and document it in changes.xml. --- src/changes/changes.xml| 6 +++ .../archivers/zip/ZipArchiveInputStreamTest.java | 50 ++ 2 files changed, 56 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index c55b876..13c8b5d 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -236,6 +236,12 @@ The type attribute can be add,update,fix,remove. Github Pull Request #127. Update actions/setup-java from v1.4.1 to v1.4.2 #133. + +Fix for the CFH signature detect in ZipArchiveInputStream. +The problem could be reproduced by a zip archive with Data +Descriptor and STORED, and without the Data Descriptor +signature. + diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java index 9175476..c1112bc 100644 --- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java @@ -29,6 +29,7 @@ import static org.junit.Assert.fail; import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.EOFException; import java.io.File; import java.io.FileInputStream; @@ -37,6 +38,7 @@ import java.io.InputStream; import java.nio.channels.Channels; import java.nio.channels.SeekableByteChannel; import java.util.Arrays; +import java.util.zip.ZipEntry; import java.util.zip.ZipException; import org.apache.commons.compress.archivers.ArchiveEntry; @@ -728,6 +730,15 @@ public class ZipArchiveInputStreamTest { } } +@Test +public void testZipUsingStoredWithDDAndNoDDSignature() throws IOException { +try (InputStream inputStream = forgeZipInputStream(); + ZipArchiveInputStream zipInputStream = new ZipArchiveInputStream(inputStream, "UTF-8", true, true);) { +while (zipInputStream.getNextZipEntry() != null) { +} +} +} + private static byte[] readEntry(final ZipArchiveInputStream zip, final ZipArchiveEntry zae) throws IOException { final int len = (int)zae.getSize(); final byte[] buff = new byte[len]; @@ -764,4 +775,43 @@ public class ZipArchiveInputStreamTest { IOUtils.toByteArray(ais); } } + +/** + * Forge a zip archive in memory, using STORED and + * Data Descriptor, and without signature of Data + * Descriptor. + * + * @return the input stream of the generated zip + * @throws IOException there are problems + */ +private InputStream forgeZipInputStream() throws IOException { +try (final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + final ZipArchiveOutputStream zo = new ZipArchiveOutputStream(byteArrayOutputStream);){ + +final ZipArchiveEntry entryA = new ZipArchiveEntry("foo"); +entryA.setMethod(ZipEntry.STORED); +entryA.setSize(4); +entryA.setCrc(0xb63cfbcdl); +zo.putArchiveEntry(entryA); +zo.write(new byte[] { 1, 2, 3, 4 }); +zo.closeArchiveEntry(); +zo.close(); + +final byte[] zipContent = byteArrayOutputStream.toByteArray(); +final byte[] old = Arrays.copyOf(zipContent, zipContent.length); + +final byte[] zipContentWithDataDescriptor = new byte[zipContent.length + 12]; +System.arraycopy(zipContent, 0, zipContentWithDataDescriptor, 0, 37); +// modify the general purpose bit flag +zipContentWithDataDescriptor[6] = 8; + +// copy the crc-32, compressed size and uncompressed size to the data descriptor +System.arraycopy(zipContent, 14, zipContentWithDataDescriptor, 37, 12); + +// and copy the rest of the zip content +System.arraycopy(zipContent, 37, zipContentWithDataDescriptor, 49, zipContent.length - 37); + +return new ByteArrayInputStream(zipContentWithDataDescriptor); +} +} }
[commons-compress] branch master updated: COMPRESS-553 : fix for pax header of tar
This is an automated email from the ASF dual-hosted git repository. peterlee 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 555daa4 COMPRESS-553 : fix for pax header of tar 555daa4 is described below commit 555daa4e9bfca0df3449f5484d5b87a5194a5abd Author: PeterAlfredLee AuthorDate: Wed Oct 7 10:51:00 2020 +0800 COMPRESS-553 : fix for pax header of tar The length validation in TarArchiveInputStream.parsePaxHeaders should also consider the headers with length smaller than 1 and ignore these headers. --- src/changes/changes.xml | 6 ++ .../compress/archivers/tar/TarArchiveInputStream.java| 2 +- .../archivers/tar/TarArchiveInputStreamTest.java | 15 --- src/test/resources/COMPRESS-553.tar | Bin 0 -> 7168 bytes 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 13c8b5d..f371886 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -242,6 +242,12 @@ The type attribute can be add,update,fix,remove. Descriptor and STORED, and without the Data Descriptor signature. + +The length validation in TarArchiveInputStream.parsePaxHeaders +should also consider the headers with length smaller than 1 +and ignore these headers. + diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java index 62766f2..cecef21 100644 --- a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java @@ -754,7 +754,7 @@ public class TarArchiveInputStream extends ArchiveInputStream { final String keyword = coll.toString(CharsetNames.UTF_8); // Get rest of entry final int restLen = len - read; -if (restLen == 1) { // only NL +if (restLen <= 1) { // only NL headers.remove(keyword); } else { final byte[] rest = new byte[restLen]; diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java index 69841d9..31e6f1b 100644 --- a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java @@ -444,7 +444,7 @@ public class TarArchiveInputStreamTest extends AbstractTestCase { @Test(expected = IOException.class) public void testParseTarTruncatedInPadding() throws IOException { -try (FileInputStream in = new FileInputStream(getFile("./COMPRESS-544_truncated_in_padding.tar")); +try (FileInputStream in = new FileInputStream(getFile("COMPRESS-544_truncated_in_padding.tar")); TarArchiveInputStream archive = new TarArchiveInputStream(in)) { while (archive.getNextTarEntry() != null) { } @@ -453,7 +453,7 @@ public class TarArchiveInputStreamTest extends AbstractTestCase { @Test(expected = IOException.class) public void testParseTarTruncatedInContent() throws IOException { -try (FileInputStream in = new FileInputStream(getFile("./COMPRESS-544_truncated_in_content.tar")); +try (FileInputStream in = new FileInputStream(getFile("COMPRESS-544_truncated_in_content.tar")); TarArchiveInputStream archive = new TarArchiveInputStream(in)) { while (archive.getNextTarEntry() != null) { } @@ -462,7 +462,16 @@ public class TarArchiveInputStreamTest extends AbstractTestCase { @Test(expected = IOException.class) public void testThrowExceptionWithNullEntry() throws IOException { -try (FileInputStream in = new FileInputStream(getFile("./COMPRESS-554.tar")); +try (FileInputStream in = new FileInputStream(getFile("COMPRESS-554.tar")); + TarArchiveInputStream archive = new TarArchiveInputStream(in)) { +while (archive.getNextTarEntry() != null) { +} +} +} + +@Test(expected = IOException.class) +public void testThrowException() throws IOException { +try (FileInputStream in = new FileInputStream(getFile("COMPRESS-553.tar")); TarArchiveInputStream archive = new TarArchiveInputStream(in)) { while (archive.getNextTarEntry() != null) {
[commons-compress] branch master updated: update CRLF to LF
This is an automated email from the ASF dual-hosted git repository. peterlee 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 5c6f14c update CRLF to LF 5c6f14c is described below commit 5c6f14c3f3076298db6578a35168966b5df4c30d Author: PeterAlfredLee AuthorDate: Tue Oct 13 17:08:54 2020 +0800 update CRLF to LF --- .gitignore | 14 +++--- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index a868385..aae2af5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,9 @@ -target -.project -.classpath -.settings -.idea -*.iml -*~ +target +.project +.classpath +.settings +.idea +*.iml +*~ /.externalToolBuilders/ /maven-eclipse.xml
[commons-compress] branch master updated: Modify some calls of method Collection.toArray
This is an automated email from the ASF dual-hosted git repository. peterlee 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 ef3cad0 Modify some calls of method Collection.toArray ef3cad0 is described below commit ef3cad07da846a9a0a2b9112c4f8859e10926e3d Author: PeterAlfredLee AuthorDate: Fri Oct 30 15:02:05 2020 +0800 Modify some calls of method Collection.toArray Use method with empty array instead of pre size array, cause it's thread safe and faster. --- .../org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java | 3 +-- .../java/org/apache/commons/compress/archivers/zip/ZipFile.java | 2 +- .../compress/archivers/zip/ZipSplitReadOnlySeekableByteChannel.java | 6 ++ 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java b/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java index dd22f03..a1600bc 100644 --- a/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java +++ b/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java @@ -219,8 +219,7 @@ public class ExtraFieldUtils { } } -final ZipExtraField[] result = new ZipExtraField[v.size()]; -return v.toArray(result); +return v.toArray(new ZipExtraField[0]); } /** diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java index 0b1e27b..f46ae5b 100644 --- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java +++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java @@ -439,7 +439,7 @@ public class ZipFile implements Closeable { * @since 1.1 */ public Enumeration getEntriesInPhysicalOrder() { -final ZipArchiveEntry[] allEntries = entries.toArray(new ZipArchiveEntry[entries.size()]); +final ZipArchiveEntry[] allEntries = entries.toArray(new ZipArchiveEntry[0]); Arrays.sort(allEntries, offsetComparator); return Collections.enumeration(Arrays.asList(allEntries)); } diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipSplitReadOnlySeekableByteChannel.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipSplitReadOnlySeekableByteChannel.java index 7c98584..3756198 100644 --- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipSplitReadOnlySeekableByteChannel.java +++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipSplitReadOnlySeekableByteChannel.java @@ -143,8 +143,7 @@ public class ZipSplitReadOnlySeekableByteChannel extends MultiReadOnlySeekableBy } channelsList.add(lastSegmentChannel); -final SeekableByteChannel[] channelArray = new SeekableByteChannel[channelsList.size()]; -return forOrderedSeekableByteChannels(channelsList.toArray(channelArray)); +return forOrderedSeekableByteChannels(channelsList.toArray(new SeekableByteChannel[0])); } /** @@ -226,8 +225,7 @@ public class ZipSplitReadOnlySeekableByteChannel extends MultiReadOnlySeekableBy } filesList.add(lastSegmentFile); -final File[] filesArray = new File[filesList.size()]; -return forFiles(filesList.toArray(filesArray)); +return forFiles(filesList.toArray(new File[0])); } private static class ZipSplitSegmentComparator implements Comparator, Serializable {
[commons-compress] branch master updated: COMPRESS-509 : document this change in changes.xml
This is an automated email from the ASF dual-hosted git repository. peterlee 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 6c53849 COMPRESS-509 : document this change in changes.xml 6c53849 is described below commit 6c5384984df236ba5f5d75a5c36031c4f03250f9 Author: PeterAlfredLee AuthorDate: Fri Nov 13 19:53:37 2020 +0800 COMPRESS-509 : document this change in changes.xml --- src/changes/changes.xml | 6 ++ 1 file changed, 6 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 2cc9331..aa5814d 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -68,6 +68,12 @@ The type attribute can be add,update,fix,remove. when reading the first entry multiple times by random access. + +Add '/' to directories with long name in tar. This is to +resolve the ambiguous behavior of the TarArchiveEntry.getName() +method between directory with short name and long name. + Removed the PowerMock dependency.
[commons-compress] branch master updated: document COMPRESS-558 in changes.xml
This is an automated email from the ASF dual-hosted git repository. peterlee 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 de1f857 document COMPRESS-558 in changes.xml de1f857 is described below commit de1f857a368c51dafff2d407890775286d19 Author: PeterAlfredLee AuthorDate: Fri Nov 13 21:58:22 2020 +0800 document COMPRESS-558 in changes.xml --- src/changes/changes.xml | 7 +++ 1 file changed, 7 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index aa5814d..7ae502f 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -263,6 +263,13 @@ The type attribute can be add,update,fix,remove. Update Mockito 1.10.19 -> 3.6.0. + +Fix accidentally added '/' to file names. +This problem is caused by the incomplete fix of +COMPRESS-509. +Github Pull Request #151. +
[commons-compress] branch master updated: COMPRESS-558: Fix accidentally added / to file names
This is an automated email from the ASF dual-hosted git repository. peterlee 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 4f52e4a COMPRESS-558: Fix accidentally added / to file names 4f52e4a is described below commit 4f52e4a712ec47bd8360fee5e14dc591ed27ba85 Author: theobisproject AuthorDate: Fri Nov 13 10:23:13 2020 +0100 COMPRESS-558: Fix accidentally added / to file names --- .../archivers/tar/TarArchiveInputStream.java | 6 ++--- .../archivers/tar/TarArchiveInputStreamTest.java | 26 ++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java index 1f532b7..cdaf692 100644 --- a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java @@ -409,11 +409,11 @@ public class TarArchiveInputStream extends ArchiveInputStream { } // COMPRESS-509 : the name of directories should end with '/' -String name = zipEncoding.decode(longNameData); +final String name = zipEncoding.decode(longNameData); +currEntry.setName(name); if (currEntry.isDirectory() && !name.endsWith("/")) { -name += "/"; +currEntry.setName(name + "/"); } -currEntry.setName(name); } if (currEntry.isGlobalPaxHeader()){ // Process Global Pax headers diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java index 31e6f1b..2103394 100644 --- a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java @@ -478,6 +478,32 @@ public class TarArchiveInputStreamTest extends AbstractTestCase { } } +@Test +public void testCompress558() throws IOException { +final String folderName = "apache-activemq-5.16.0/examples/openwire/advanced-scenarios/jms-example-exclusive-consumer/src/main/"; +final String consumerJavaName = "apache-activemq-5.16.0/examples/openwire/advanced-scenarios/jms-example-exclusive-consumer/src/main/java/example/queue/exclusive/Consumer.java"; +final String producerJavaName = "apache-activemq-5.16.0/examples/openwire/advanced-scenarios/jms-example-exclusive-consumer/src/main/java/example/queue/exclusive/Producer.java"; + +final ByteArrayOutputStream bos = new ByteArrayOutputStream(); +try (final TarArchiveOutputStream tos = new TarArchiveOutputStream(bos)) { +tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); +TarArchiveEntry rootfolder = new TarArchiveEntry(folderName); +tos.putArchiveEntry(rootfolder); +TarArchiveEntry consumerJava = new TarArchiveEntry(consumerJavaName); +tos.putArchiveEntry(consumerJava); +TarArchiveEntry producerJava = new TarArchiveEntry(producerJavaName); +tos.putArchiveEntry(producerJava); +tos.closeArchiveEntry(); +} +final byte[] data = bos.toByteArray(); +try (final ByteArrayInputStream bis = new ByteArrayInputStream(data); + final TarArchiveInputStream tis = new TarArchiveInputStream(bis)) { +assertEquals(folderName, tis.getNextTarEntry().getName()); +assertEquals(consumerJavaName, tis.getNextTarEntry().getName()); +assertEquals(producerJavaName, tis.getNextTarEntry().getName()); +} +} + private TarArchiveInputStream getTestStream(final String name) { return new TarArchiveInputStream( TarArchiveInputStreamTest.class.getResourceAsStream(name));
[commons-compress] branch master updated (0bff34c -> 291b49d)
This is an automated email from the ASF dual-hosted git repository. peterlee pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git. from 0bff34c Redundant return. new b86feb6 COMPRESS-560: Do not return false if the entry is a tar sparse entry new 7d00426 COMPRESS-560: Use assumeTrue/assumeFalse to check if the test should be run on the current OS new 291b49d COMPRESS-560: Add message to assume check The 3 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference. Summary of changes: .../archivers/tar/TarArchiveInputStream.java | 8 +-- .../compress/archivers/tar/SparseFilesTest.java| 77 -- 2 files changed, 43 insertions(+), 42 deletions(-)
[commons-compress] 02/03: COMPRESS-560: Use assumeTrue/assumeFalse to check if the test should be run on the current OS
This is an automated email from the ASF dual-hosted git repository. peterlee pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git commit 7d004266d31d6bbbc0560159d39c04fec02abb9a Author: theobisproject AuthorDate: Sun Nov 22 14:09:33 2020 +0100 COMPRESS-560: Use assumeTrue/assumeFalse to check if the test should be run on the current OS --- .../compress/archivers/tar/SparseFilesTest.java| 18 ++ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java index 49f49e1..136aef3 100644 --- a/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java @@ -19,6 +19,8 @@ package org.apache.commons.compress.archivers.tar; import static org.junit.Assert.*; +import static org.junit.Assume.assumeFalse; +import static org.junit.Assume.assumeTrue; import org.apache.commons.compress.AbstractTestCase; import org.apache.commons.compress.utils.IOUtils; @@ -73,9 +75,7 @@ public class SparseFilesTest extends AbstractTestCase { @Test public void testExtractSparseTarsOnWindows() throws IOException { -if (!isOnWindows) { -return; -} +assumeTrue(isOnWindows); final File oldGNUSparseTar = getFile("oldgnu_sparse.tar"); final File paxGNUSparseTar = getFile("pax_gnu_sparse.tar"); @@ -115,9 +115,7 @@ public class SparseFilesTest extends AbstractTestCase { @Test public void testExtractOldGNU() throws IOException, InterruptedException { -if (isOnWindows) { -return; -} +assumeFalse(isOnWindows); try { final File file = getFile("oldgnu_sparse.tar"); @@ -136,9 +134,7 @@ public class SparseFilesTest extends AbstractTestCase { @Test public void testExtractExtendedOldGNU() throws IOException, InterruptedException { -if (isOnWindows) { -return; -} +assumeFalse(isOnWindows); final File file = getFile("oldgnu_extended_sparse.tar"); try (InputStream sparseFileInputStream = extractTarAndGetInputStream(file, "sparse6"); @@ -177,9 +173,7 @@ public class SparseFilesTest extends AbstractTestCase { @Test public void testExtractPaxGNU() throws IOException, InterruptedException { -if (isOnWindows) { -return; -} +assumeFalse(isOnWindows); final File file = getFile("pax_gnu_sparse.tar"); try (TarArchiveInputStream tin = new TarArchiveInputStream(new FileInputStream(file))) {
[commons-compress] 01/03: COMPRESS-560: Do not return false if the entry is a tar sparse entry
This is an automated email from the ASF dual-hosted git repository. peterlee pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git commit b86feb61e7d96e36c9348b4c4ac9ead331fc714a Author: theobisproject AuthorDate: Sun Nov 22 14:07:21 2020 +0100 COMPRESS-560: Do not return false if the entry is a tar sparse entry --- .../archivers/tar/TarArchiveInputStream.java | 8 +-- .../compress/archivers/tar/SparseFilesTest.java| 59 +- 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java index cdaf692..ea68d7c 100644 --- a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java @@ -1006,15 +1006,11 @@ public class TarArchiveInputStream extends ArchiveInputStream { /** * Whether this class is able to read the given entry. * - * May return false if the current entry is a sparse file. + * @return The implementation will return true if the {@link ArchiveEntry} is an instance of {@link TarArchiveEntry} */ @Override public boolean canReadEntryData(final ArchiveEntry ae) { -if (ae instanceof TarArchiveEntry) { -final TarArchiveEntry te = (TarArchiveEntry) ae; -return !te.isSparse(); -} -return false; +return ae instanceof TarArchiveEntry; } /** diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java index d528b65..49f49e1 100644 --- a/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java @@ -45,7 +45,7 @@ public class SparseFilesTest extends AbstractTestCase { assertTrue(ae.isOldGNUSparse()); assertTrue(ae.isGNUSparse()); assertFalse(ae.isPaxGNUSparse()); -assertFalse(tin.canReadEntryData(ae)); +assertTrue(tin.canReadEntryData(ae)); final List sparseHeaders = ae.getSparseHeaders(); assertEquals(3, sparseHeaders.size()); @@ -82,27 +82,33 @@ public class SparseFilesTest extends AbstractTestCase { try (TarArchiveInputStream paxGNUSparseInputStream = new TarArchiveInputStream(new FileInputStream(paxGNUSparseTar))) { // compare between old GNU and PAX 0.0 -paxGNUSparseInputStream.getNextTarEntry(); +TarArchiveEntry paxGNUEntry = paxGNUSparseInputStream.getNextTarEntry(); +assertTrue(paxGNUSparseInputStream.canReadEntryData(paxGNUEntry)); try (TarArchiveInputStream oldGNUSparseInputStream = new TarArchiveInputStream(new FileInputStream(oldGNUSparseTar))) { -oldGNUSparseInputStream.getNextTarEntry(); +final TarArchiveEntry oldGNUEntry = oldGNUSparseInputStream.getNextTarEntry(); + assertTrue(oldGNUSparseInputStream.canReadEntryData(oldGNUEntry)); assertArrayEquals(IOUtils.toByteArray(oldGNUSparseInputStream), -IOUtils.toByteArray(paxGNUSparseInputStream)); +IOUtils.toByteArray(paxGNUSparseInputStream)); } // compare between old GNU and PAX 0.1 -paxGNUSparseInputStream.getNextTarEntry(); +paxGNUEntry = paxGNUSparseInputStream.getNextTarEntry(); +assertTrue(paxGNUSparseInputStream.canReadEntryData(paxGNUEntry)); try (TarArchiveInputStream oldGNUSparseInputStream = new TarArchiveInputStream(new FileInputStream(oldGNUSparseTar))) { -oldGNUSparseInputStream.getNextTarEntry(); +final TarArchiveEntry oldGNUEntry = oldGNUSparseInputStream.getNextTarEntry(); + assertTrue(oldGNUSparseInputStream.canReadEntryData(oldGNUEntry)); assertArrayEquals(IOUtils.toByteArray(oldGNUSparseInputStream), -IOUtils.toByteArray(paxGNUSparseInputStream)); +IOUtils.toByteArray(paxGNUSparseInputStream)); } // compare between old GNU and PAX 1.0 -paxGNUSparseInputStream.getNextTarEntry(); +paxGNUEntry = paxGNUSparseInputStream.getNextTarEntry(); +assertTrue(paxGNUSparseInputStream.canReadEntryData(paxGNUEntry)); try (TarArchiveInputStream oldGNUSparseInputStream = new TarArchiveInputStream(new FileInputStream(oldGNUSparseTar))) { -oldGNUSparseInputStream.getNextTarEntry(); +final TarArchiveEntry oldGNUEntry = oldGNUSparseInputStream.getNextTarEntry(); + assertTrue
[commons-compress] 03/03: COMPRESS-560: Add message to assume check
This is an automated email from the ASF dual-hosted git repository. peterlee pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git commit 291b49d2f36b2e21f209a6eb2913db2ddaf6fef8 Author: theobisproject AuthorDate: Fri Nov 27 16:30:35 2020 +0100 COMPRESS-560: Add message to assume check --- .../apache/commons/compress/archivers/tar/SparseFilesTest.java| 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java index 136aef3..434fa64 100644 --- a/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java @@ -75,7 +75,7 @@ public class SparseFilesTest extends AbstractTestCase { @Test public void testExtractSparseTarsOnWindows() throws IOException { -assumeTrue(isOnWindows); +assumeTrue("This test should be ignored if not running on Windows", isOnWindows); final File oldGNUSparseTar = getFile("oldgnu_sparse.tar"); final File paxGNUSparseTar = getFile("pax_gnu_sparse.tar"); @@ -115,7 +115,7 @@ public class SparseFilesTest extends AbstractTestCase { @Test public void testExtractOldGNU() throws IOException, InterruptedException { -assumeFalse(isOnWindows); +assumeFalse("This test should be ignored on Windows", isOnWindows); try { final File file = getFile("oldgnu_sparse.tar"); @@ -134,7 +134,7 @@ public class SparseFilesTest extends AbstractTestCase { @Test public void testExtractExtendedOldGNU() throws IOException, InterruptedException { -assumeFalse(isOnWindows); +assumeFalse("This test should be ignored on Windows", isOnWindows); final File file = getFile("oldgnu_extended_sparse.tar"); try (InputStream sparseFileInputStream = extractTarAndGetInputStream(file, "sparse6"); @@ -173,7 +173,7 @@ public class SparseFilesTest extends AbstractTestCase { @Test public void testExtractPaxGNU() throws IOException, InterruptedException { -assumeFalse(isOnWindows); +assumeFalse("This test should be ignored on Windows", isOnWindows); final File file = getFile("pax_gnu_sparse.tar"); try (TarArchiveInputStream tin = new TarArchiveInputStream(new FileInputStream(file))) {
[commons-compress] branch master updated: document pull request #153
This is an automated email from the ASF dual-hosted git repository. peterlee 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 1258341 document pull request #153 1258341 is described below commit 1258341b941928b587102fd2b29574e00621087a Author: PeterAlfredLee AuthorDate: Mon Nov 30 09:51:24 2020 +0800 document pull request #153 --- src/changes/changes.xml | 7 +++ 1 file changed, 7 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 7ae502f..6406761 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -270,6 +270,13 @@ The type attribute can be add,update,fix,remove. COMPRESS-509. Github Pull Request #151. + +As sparse entries can be successfully parsed now, +TarArchiveInputStream.canReadEntryData should return +true if the entry is a sparse entry. +Github Pull Request #153. +
[commons-compress] branch master updated: do not use wildcard imports
This is an automated email from the ASF dual-hosted git repository. peterlee 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 05a995e do not use wildcard imports 05a995e is described below commit 05a995ee725f153b39be111c8b51adbed24d30a4 Author: PeterAlfredLee AuthorDate: Mon Nov 30 10:01:39 2020 +0800 do not use wildcard imports --- .../compress/compressors/deflate64/HuffmanDecoder.java| 5 - .../org/apache/commons/compress/AbstractTestCase.java | 4 +++- .../org/apache/commons/compress/ArchiveUtilsTest.java | 5 - .../org/apache/commons/compress/ChainingTestCase.java | 3 ++- .../apache/commons/compress/DetectArchiverTestCase.java | 4 +++- .../java/org/apache/commons/compress/IOMethodsTest.java | 4 +++- .../org/apache/commons/compress/archivers/ArTestCase.java | 5 - .../compress/archivers/ArchiveOutputStreamTest.java | 2 +- .../apache/commons/compress/archivers/CpioTestCase.java | 5 - .../apache/commons/compress/archivers/DumpTestCase.java | 2 +- .../commons/compress/archivers/ExceptionMessageTest.java | 4 +++- .../apache/commons/compress/archivers/SevenZTestCase.java | 2 +- .../compress/archivers/ar/ArArchiveInputStreamTest.java | 15 +++ .../compress/archivers/ar/ArArchiveOutputStreamTest.java | 3 ++- .../compress/archivers/arj/ArjArchiveInputStreamTest.java | 3 ++- .../archivers/cpio/CpioArchiveInputStreamTest.java| 3 ++- .../archivers/cpio/CpioArchiveOutputStreamTest.java | 3 ++- .../archivers/dump/DumpArchiveInputStreamTest.java| 5 - .../archivers/jar/JarArchiveOutputStreamTest.java | 4 +++- .../compress/archivers/memory/MemoryArchiveTestCase.java | 4 +++- .../archivers/sevenz/AES256SHA256DecoderTest.java | 3 ++- .../commons/compress/archivers/sevenz/SevenZFileTest.java | 9 - .../compress/archivers/sevenz/SevenZOutputFileTest.java | 7 ++- .../commons/compress/archivers/tar/SparseFilesTest.java | 6 +- .../commons/compress/archivers/zip/AsiExtraFieldTest.java | 5 - .../commons/compress/archivers/zip/BinaryTreeTest.java| 4 +++- .../commons/compress/archivers/zip/BitStreamTest.java | 2 +- .../compress/archivers/zip/CircularBufferTest.java| 4 +++- .../compress/archivers/zip/EncryptedArchiveTest.java | 6 +- .../compress/archivers/zip/ExplodeSupportTest.java| 4 +++- .../compress/archivers/zip/ExtraFieldUtilsTest.java | 4 +++- .../compress/archivers/zip/GeneralPurposeBitTest.java | 5 - .../compress/archivers/zip/Maven221MultiVolumeTest.java | 3 ++- .../commons/compress/archivers/zip/ScatterSampleTest.java | 2 +- .../commons/compress/archivers/zip/UTF8ZipFilesTest.java | 4 +++- .../zip/Zip64ExtendedInformationExtraFieldTest.java | 3 ++- .../compress/archivers/zip/ZipArchiveEntryTest.java | 6 +- .../compress/archivers/zip/ZipEightByteIntegerTest.java | 3 ++- .../commons/compress/archivers/zip/ZipFileTest.java | 8 +++- .../commons/compress/archivers/zip/ZipLongTest.java | 4 +++- .../commons/compress/archivers/zip/ZipShortTest.java | 4 +++- .../commons/compress/archivers/zip/ZipUtilTest.java | 4 +++- .../commons/compress/changes/ChangeSetTestCase.java | 3 ++- .../commons/compress/compressors/BZip2TestCase.java | 2 +- .../commons/compress/compressors/BZip2UtilsTestCase.java | 4 +++- .../compress/compressors/FramedSnappyTestCase.java| 3 ++- .../apache/commons/compress/compressors/GZipTestCase.java | 3 ++- .../commons/compress/compressors/GzipUtilsTestCase.java | 4 +++- .../commons/compress/compressors/Pack200TestCase.java | 4 +++- .../apache/commons/compress/compressors/XZTestCase.java | 2 +- .../apache/commons/compress/compressors/ZTestCase.java| 3 ++- .../lz4/FramedLZ4CompressorInputStreamTest.java | 9 +++-- .../compress/compressors/lzma/LZMAUtilsTestCase.java | 4 +++- .../snappy/FramedSnappyCompressorInputStreamTest.java | 6 +- .../commons/compress/compressors/xz/XZUtilsTestCase.java | 4 +++- .../org/apache/commons/compress/utils/ByteUtilsTest.java | 5 - .../utils/ChecksumCalculatingInputStreamTest.java | 3 ++- 57 files changed, 183 insertions(+), 61 deletions(-) diff --git a/src/main/java/org/apache/commons/compress/compressors/deflate64/HuffmanDecoder.java b/src/main/java/org/apache/commons/compress/compressors/deflate64/HuffmanDecoder.java index fe45130..2baebea 100644 --- a/src/main/java/org/apache/commons/compress/compressors/deflate64/HuffmanDecoder.java +++ b/src/main/java/org/apache/commons/compress/compressors/deflate64/HuffmanDecoder.java @@ -26,7 +26,10 @@ import java.io.InputStream; import java.nio.ByteOrder; import java.util.Arrays; -import
[commons-compress] branch master updated (05a995e -> d98e849)
This is an automated email from the ASF dual-hosted git repository. peterlee pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git. from 05a995e do not use wildcard imports new 75a16c2 COMPRESS-559: Extract sparsefile-0.1 also on Linux new d98e849 COMPRESS-559: Skip extracting with GNU tar 1.28 The 2 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference. Summary of changes: .../commons/compress/archivers/tar/SparseFilesTest.java| 14 +++--- 1 file changed, 11 insertions(+), 3 deletions(-)
[commons-compress] 02/02: COMPRESS-559: Skip extracting with GNU tar 1.28
This is an automated email from the ASF dual-hosted git repository. peterlee pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git commit d98e849850a33c1762d318108cb21d8e210388fc Author: theobisproject AuthorDate: Tue Dec 8 20:49:11 2020 +0100 COMPRESS-559: Skip extracting with GNU tar 1.28 It is known to be broken for the archive the test will extract --- .../apache/commons/compress/archivers/tar/SparseFilesTest.java | 10 ++ 1 file changed, 10 insertions(+) diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java index fad2fc8..ab41002 100644 --- a/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java @@ -178,6 +178,8 @@ public class SparseFilesTest extends AbstractTestCase { @Test public void testExtractPaxGNU() throws IOException, InterruptedException { assumeFalse("This test should be ignored on Windows", isOnWindows); +assumeFalse("This test should be ignored if GNU tar is version 1.28", +getTarBinaryHelp().startsWith("tar (GNU tar) 1.28")); final File file = getFile("pax_gnu_sparse.tar"); try (TarArchiveInputStream tin = new TarArchiveInputStream(new FileInputStream(file))) { @@ -241,5 +243,13 @@ public class SparseFilesTest extends AbstractTestCase { fail("didn't find " + sparseFileName + " after extracting " + tarFile); return null; } + +private String getTarBinaryHelp() throws IOException { +final ProcessBuilder pb = new ProcessBuilder("tar", "--version"); +pb.redirectErrorStream(true); +final Process process = pb.start(); +// wait until the help is shown +return new String(IOUtils.toByteArray(process.getInputStream())); +} }
[commons-compress] 01/02: COMPRESS-559: Extract sparsefile-0.1 also on Linux
This is an automated email from the ASF dual-hosted git repository. peterlee pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git commit 75a16c23c73010988dc6dad08397ab4cc51e3533 Author: theobisproject AuthorDate: Sun Nov 22 13:58:56 2020 +0100 COMPRESS-559: Extract sparsefile-0.1 also on Linux --- .../org/apache/commons/compress/archivers/tar/SparseFilesTest.java| 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java index 3b76696..fad2fc8 100644 --- a/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java @@ -189,11 +189,9 @@ public class SparseFilesTest extends AbstractTestCase { IOUtils.toByteArray(sparseFileInputStream)); } -// TODO : it's wired that I can only get a 0 size sparsefile-0.1 on my Ubuntu 16.04 -//using "tar -xf pax_gnu_sparse.tar" paxGNUEntry = tin.getNextTarEntry(); assertTrue(tin.canReadEntryData(paxGNUEntry)); -try (InputStream sparseFileInputStream = extractTarAndGetInputStream(file, "sparsefile-0.0")) { +try (InputStream sparseFileInputStream = extractTarAndGetInputStream(file, "sparsefile-0.1")) { assertArrayEquals(IOUtils.toByteArray(tin), IOUtils.toByteArray(sparseFileInputStream)); }
[commons-compress] branch master updated: document COMPRESS-559 and make some comments
This is an automated email from the ASF dual-hosted git repository. peterlee 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 4cf5b34 document COMPRESS-559 and make some comments 4cf5b34 is described below commit 4cf5b340bfb881457fc03819f1b2a651c798c5af Author: PeterAlfredLee AuthorDate: Thu Dec 10 14:56:49 2020 +0800 document COMPRESS-559 and make some comments --- src/changes/changes.xml | 6 ++ .../org/apache/commons/compress/archivers/tar/SparseFilesTest.java | 3 +++ 2 files changed, 9 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 6406761..59aa94e 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -277,6 +277,12 @@ The type attribute can be add,update,fix,remove. true if the entry is a sparse entry. Github Pull Request #153. + +SparseFilesTest#testExtractPaxGNU should be skipped +if the version of GNU tar binary is 1.28. +Github Pull Request #152. + diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java index ab41002..852455d 100644 --- a/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java @@ -178,6 +178,9 @@ public class SparseFilesTest extends AbstractTestCase { @Test public void testExtractPaxGNU() throws IOException, InterruptedException { assumeFalse("This test should be ignored on Windows", isOnWindows); +// GNU tar with version 1.28 has some problems reading sparsefile-0.1, +// so the test should be skipped then +// TODO : what about the versions lower than 1.28? assumeFalse("This test should be ignored if GNU tar is version 1.28", getTarBinaryHelp().startsWith("tar (GNU tar) 1.28"));
[commons-compress] branch master updated (1470c26 -> ffc5c18)
This is an automated email from the ASF dual-hosted git repository. peterlee pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git. from 1470c26 Fix spelling. new d462ac4 COMPRESS-561 - Minor improvement new ffc5c18 Add final The 2 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference. Summary of changes: .../archivers/ar/ArArchiveOutputStream.java| 9 .../archivers/cpio/CpioArchiveInputStream.java | 2 +- .../archivers/cpio/CpioArchiveOutputStream.java| 2 +- .../archivers/dump/DumpArchiveConstants.java | 4 ++-- .../compress/archivers/dump/DumpArchiveEntry.java | 4 ++-- .../archivers/dump/DumpArchiveInputStream.java | 6 +++--- .../BoundedSeekableByteChannelInputStream.java | 4 ++-- .../commons/compress/archivers/sevenz/Coders.java | 4 ++-- .../compress/archivers/sevenz/SevenZFile.java | 5 +++-- .../compress/archivers/sevenz/SevenZMethod.java| 5 +++-- .../archivers/tar/TarArchiveInputStream.java | 2 +- .../archivers/tar/TarArchiveOutputStream.java | 2 +- .../compress/archivers/zip/AsiExtraField.java | 9 .../commons/compress/archivers/zip/BinaryTree.java | 9 .../archivers/zip/ExplodingInputStream.java| 2 +- .../compress/archivers/zip/ExtraFieldUtils.java| 25 -- .../compress/archivers/zip/ZipArchiveEntry.java| 2 +- .../archivers/zip/ZipArchiveInputStream.java | 2 +- .../archivers/zip/ZipArchiveOutputStream.java | 13 +-- .../commons/compress/archivers/zip/ZipFile.java| 4 ++-- .../zip/ZipSplitReadOnlySeekableByteChannel.java | 2 +- .../compress/compressors/brotli/BrotliUtils.java | 2 +- .../bzip2/BZip2CompressorInputStream.java | 2 +- .../compress/compressors/bzip2/BlockSort.java | 4 ++-- .../compressors/deflate64/HuffmanDecoder.java | 2 +- .../gzip/GzipCompressorInputStream.java| 2 +- .../lz4/BlockLZ4CompressorOutputStream.java| 3 ++- .../lz4/FramedLZ4CompressorOutputStream.java | 13 +-- .../snappy/SnappyCompressorInputStream.java| 2 +- .../compress/compressors/zstandard/ZstdUtils.java | 2 +- .../commons/compress/utils/ArchiveUtils.java | 2 +- .../commons/compress/utils/BitInputStream.java | 2 +- .../apache/commons/compress/AbstractTestCase.java | 2 +- .../commons/compress/archivers/ZipTestCase.java| 6 +++--- .../compress/archivers/examples/ExpanderTest.java | 2 +- .../archivers/memory/MemoryArchiveInputStream.java | 7 +++--- .../compress/archivers/sevenz/SevenZFileTest.java | 2 +- .../archivers/sevenz/SevenZNativeHeapTest.java | 4 ++-- .../commons/compress/archivers/tar/TarLister.java | 2 +- .../compress/archivers/zip/DataDescriptorTest.java | 4 ++-- .../commons/compress/archivers/zip/Lister.java | 7 +++--- .../compress/archivers/zip/ScatterSample.java | 4 ++-- .../compress/archivers/zip/UTF8ZipFilesTest.java | 3 +-- .../archivers/zip/ZipArchiveEntryTest.java | 2 +- .../archivers/zip/ZipArchiveInputStreamTest.java | 10 - .../archivers/zip/ZipSplitOutputStreamTest.java| 2 +- .../commons/compress/compressors/GZipTestCase.java | 6 +++--- .../commons/compress/compressors/LZMATestCase.java | 2 +- .../bzip2/PythonTruncatedBzip2Test.java| 2 +- .../lz4/BlockLZ4CompressorRoundtripTest.java | 2 +- .../lz4/FramedLZ4CompressorInputStreamTest.java| 2 +- .../commons/compress/utils/CharsetsTest.java | 4 ++-- .../utils/FixedLengthBlockOutputStreamTest.java| 7 +++--- .../MultiReadOnlySeekableByteChannelTest.java | 2 +- .../ZipSplitReadOnlySeekableByteChannelTest.java | 2 +- 55 files changed, 125 insertions(+), 114 deletions(-)
[commons-compress] 01/02: COMPRESS-561 - Minor improvement
This is an automated email from the ASF dual-hosted git repository. peterlee pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git commit d462ac40c2053d25d4224cfc8e7a86a68371f9a3 Author: Arturo Bernal AuthorDate: Sat Dec 12 16:34:33 2020 +0100 COMPRESS-561 - Minor improvement --- .../archivers/ar/ArArchiveOutputStream.java| 9 .../archivers/cpio/CpioArchiveInputStream.java | 2 +- .../archivers/cpio/CpioArchiveOutputStream.java| 2 +- .../archivers/dump/DumpArchiveConstants.java | 4 ++-- .../compress/archivers/dump/DumpArchiveEntry.java | 4 ++-- .../archivers/dump/DumpArchiveInputStream.java | 6 +++--- .../BoundedSeekableByteChannelInputStream.java | 4 ++-- .../commons/compress/archivers/sevenz/Coders.java | 4 ++-- .../compress/archivers/sevenz/SevenZFile.java | 5 +++-- .../compress/archivers/sevenz/SevenZMethod.java| 5 +++-- .../archivers/tar/TarArchiveInputStream.java | 2 +- .../archivers/tar/TarArchiveOutputStream.java | 2 +- .../compress/archivers/zip/AsiExtraField.java | 9 .../commons/compress/archivers/zip/BinaryTree.java | 9 .../archivers/zip/ExplodingInputStream.java| 2 +- .../compress/archivers/zip/ExtraFieldUtils.java| 25 -- .../compress/archivers/zip/ZipArchiveEntry.java| 2 +- .../archivers/zip/ZipArchiveInputStream.java | 2 +- .../archivers/zip/ZipArchiveOutputStream.java | 13 +-- .../commons/compress/archivers/zip/ZipFile.java| 4 ++-- .../zip/ZipSplitReadOnlySeekableByteChannel.java | 2 +- .../compress/compressors/brotli/BrotliUtils.java | 2 +- .../bzip2/BZip2CompressorInputStream.java | 2 +- .../compress/compressors/bzip2/BlockSort.java | 4 ++-- .../compressors/deflate64/HuffmanDecoder.java | 2 +- .../lz4/BlockLZ4CompressorOutputStream.java| 3 ++- .../lz4/FramedLZ4CompressorOutputStream.java | 13 +-- .../snappy/SnappyCompressorInputStream.java| 2 +- .../compress/compressors/zstandard/ZstdUtils.java | 2 +- .../commons/compress/utils/ArchiveUtils.java | 2 +- .../commons/compress/utils/BitInputStream.java | 2 +- .../apache/commons/compress/AbstractTestCase.java | 2 +- .../commons/compress/archivers/ZipTestCase.java| 6 +++--- .../compress/archivers/examples/ExpanderTest.java | 2 +- .../archivers/memory/MemoryArchiveInputStream.java | 7 +++--- .../compress/archivers/sevenz/SevenZFileTest.java | 2 +- .../archivers/sevenz/SevenZNativeHeapTest.java | 4 ++-- .../commons/compress/archivers/tar/TarLister.java | 2 +- .../compress/archivers/zip/DataDescriptorTest.java | 4 ++-- .../commons/compress/archivers/zip/Lister.java | 7 +++--- .../compress/archivers/zip/ScatterSample.java | 4 ++-- .../compress/archivers/zip/UTF8ZipFilesTest.java | 3 +-- .../archivers/zip/ZipArchiveEntryTest.java | 2 +- .../archivers/zip/ZipArchiveInputStreamTest.java | 10 - .../archivers/zip/ZipSplitOutputStreamTest.java| 2 +- .../commons/compress/compressors/GZipTestCase.java | 6 +++--- .../commons/compress/compressors/LZMATestCase.java | 2 +- .../bzip2/PythonTruncatedBzip2Test.java| 2 +- .../lz4/BlockLZ4CompressorRoundtripTest.java | 2 +- .../lz4/FramedLZ4CompressorInputStreamTest.java| 2 +- .../commons/compress/utils/CharsetsTest.java | 4 ++-- .../utils/FixedLengthBlockOutputStreamTest.java| 7 +++--- .../MultiReadOnlySeekableByteChannelTest.java | 2 +- .../ZipSplitReadOnlySeekableByteChannelTest.java | 2 +- 54 files changed, 124 insertions(+), 113 deletions(-) diff --git a/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java b/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java index 6efd879..141eb4b 100644 --- a/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java @@ -137,14 +137,15 @@ public class ArArchiveOutputStream extends ArchiveOutputStream { boolean mustAppendName = false; final String n = pEntry.getName(); -if (LONGFILE_ERROR == longFileMode && n.length() > 16) { +final int nLength = n.length(); +if (LONGFILE_ERROR == longFileMode && nLength > 16) { throw new IOException("File name too long, > 16 chars: "+n); } if (LONGFILE_BSD == longFileMode && -(n.length() > 16 || n.contains(" "))) { +(nLength > 16 || n.contains(" "))) { mustAppendName = true; offset += write(ArArchiveInputStream.BSD_LONGNAME_PREFIX -+ String.valueOf(n.length())); ++ Strin
[commons-compress] 02/02: Add final
This is an automated email from the ASF dual-hosted git repository. peterlee pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git commit ffc5c186d2977765dcd3563b68dffb2d7ee8b42a Author: Arturo Bernal AuthorDate: Sat Dec 12 16:56:19 2020 +0100 Add final --- .../commons/compress/compressors/gzip/GzipCompressorInputStream.java| 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java b/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java index 4d7f742..ff600bc 100644 --- a/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java +++ b/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java @@ -309,7 +309,7 @@ public class GzipCompressorInputStream extends CompressorInputStream inf.setInput(buf, 0, bufUsed); } -int ret; +final int ret; try { ret = inf.inflate(b, off, len); } catch (final DataFormatException e) { // NOSONAR
[commons-compress] branch master updated (ffc5c18 -> 57bcd9b)
This is an automated email from the ASF dual-hosted git repository. peterlee pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git. from ffc5c18 Add final add 57bcd9b document COMPRESS-561 No new revisions were added by this update. Summary of changes: src/changes/changes.xml | 5 + 1 file changed, 5 insertions(+)
[commons-compress] branch master updated: add more information about allowStoredEntriesWithDataDescriptor
This is an automated email from the ASF dual-hosted git repository. peterlee 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 81299d2 add more information about allowStoredEntriesWithDataDescriptor 81299d2 is described below commit 81299d245660a7b931a445744aaf451783426f3e Author: PeterAlfredLee AuthorDate: Sat Dec 26 16:38:51 2020 +0800 add more information about allowStoredEntriesWithDataDescriptor --- .../compress/archivers/zip/ZipArchiveInputStream.java| 12 +++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java index 787caa7..6774f25 100644 --- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java @@ -114,7 +114,17 @@ public class ZipArchiveInputStream extends ArchiveInputStream implements InputSt */ private ByteArrayInputStream lastStoredEntry = null; -/** Whether the stream will try to read STORED entries that use a data descriptor. */ +/** + * Whether the stream will try to read STORED entries that use a data descriptor. + * Setting it to true means we will not stop reading a entry with the compressed + * size, instead we will stoping reading a entry when a data descriptor is met(by + * finding the Data Descriptor Signature). This will completely break down in some + * cases - like JARs in WARs. + * + * See also : + * https://issues.apache.org/jira/projects/COMPRESS/issues/COMPRESS-555 + * https://github.com/apache/commons-compress/pull/137#issuecomment-690835644 + */ private boolean allowStoredEntriesWithDataDescriptor = false; /** Count decompressed bytes for current entry */
[commons-compress] 09/13: COMPRESS-540: Implement reading of padded last record
This is an automated email from the ASF dual-hosted git repository. peterlee pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git commit a9a03f63895cabfa903415da19a581443592ee88 Author: theobisproject AuthorDate: Sat Dec 26 12:46:58 2020 +0100 COMPRESS-540: Implement reading of padded last record --- .../apache/commons/compress/archivers/tar/TarFile.java | 15 +-- .../archivers/tar/TarArchiveInputStreamTest.java | 3 +++ .../commons/compress/archivers/tar/TarFileTest.java | 16 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java index dc4ab20..664d3ee 100644 --- a/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java +++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java @@ -548,8 +548,7 @@ public class TarFile implements Closeable { if (isAtEOF() && headerBuf != null) { // Consume rest tryToConsumeSecondEOFRecord(); -// TODO: This is present in the TarArchiveInputStream but I don't know if we need this in the random access implementation. All tests are passing ... -// consumeRemainderOfLastBlock(); +consumeRemainderOfLastBlock(); headerBuf = null; } return headerBuf; @@ -580,6 +579,18 @@ public class TarFile implements Closeable { } /** + * This method is invoked once the end of the archive is hit, it + * tries to consume the remaining bytes under the assumption that + * the tool creating this archive has padded the last block. + */ +private void consumeRemainderOfLastBlock() throws IOException { +final long bytesReadOfLastBlock = archive.position() % blockSize; +if (bytesReadOfLastBlock > 0) { +archive.position(archive.position() + blockSize - bytesReadOfLastBlock); +} +} + +/** * Read a record from the input stream and return the data. * * @return The record data or null if EOF has been hit. diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java index e7907b8..b86c835 100644 --- a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java @@ -123,6 +123,9 @@ public class TarArchiveInputStreamTest extends AbstractTestCase { tis.close(); } +/** + * This test ensures the implementation is reading the padded last block if a tool has added one to an archive + */ @Test public void shouldConsumeArchiveCompletely() throws Exception { final InputStream is = TarArchiveInputStreamTest.class 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 1360320..07c8a6b 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 @@ -23,6 +23,8 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.nio.ByteBuffer; +import java.nio.channels.SeekableByteChannel; import java.nio.file.Files; import java.nio.file.Path; import java.util.Calendar; @@ -110,6 +112,20 @@ public class TarFileTest extends AbstractTestCase { } } +/** + * This test ensures the implementation is reading the padded last block if a tool has added one to an archive + */ +@Test +public void archiveWithTrailer() throws IOException { +try (final SeekableByteChannel channel = Files.newByteChannel(getPath("archive_with_trailer.tar")); + final TarFile tarfile = new TarFile(channel, TarConstants.DEFAULT_BLKSIZE, TarConstants.DEFAULT_RCDSIZE, null, false)) { +final String tarAppendix = "Hello, world!\n"; +final ByteBuffer buffer = ByteBuffer.allocate(tarAppendix.length()); +channel.read(buffer); +assertEquals(tarAppendix, new String(buffer.array())); +} +} + @Test public void readsArchiveCompletely_COMPRESS245() throws Exception { try {
[commons-compress] branch master updated (a9eabd5 -> f36fe7e)
This is an automated email from the ASF dual-hosted git repository. peterlee pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git. from a9eabd5 Remove unused import. new 81f2084 COMPRESS-540: Implement TarFile to allow random access to tar files new f11c897 COMPRESS-540: Change visibility of methods moved to TarUtils to protected new 9f7c5aa COMPRESS-540: Implement storage of data offset in tar entries via EntryStreamOffsets instead of reinventing it new 57e2b28 COMPRESS-540: Include fix for COMPRESS-544 new 3b7f0ae COMPRESS-540: Include fix for COMPRESS-554 new 6270ff5 COMPRESS-540: Include fix for COMPRESS-553 new f0aaab6 COMPRESS-540: Fix problems with long filenames new 543ac95 COMPRESS-540: Javadoc enhancement new a9a03f6 COMPRESS-540: Implement reading of padded last record new 53bc2f7 COMPRESS-540: Rename BoundedNIOInputStream -> BoundedArchiveInputStream new 20f8b3e COMPRESS-540: Include changes from COMPRESS-559 new 34759ba COMPRESS-540: Remove commented out code in test new f36fe7e COMPRESS-540: Tar entry offset should not be smaller than 0 The 13 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference. Summary of changes: .../compress/archivers/tar/TarArchiveEntry.java| 56 +- .../archivers/tar/TarArchiveInputStream.java | 229 +-- .../tar/TarArchiveSparseZeroInputStream.java} | 31 +- .../commons/compress/archivers/tar/TarFile.java| 747 + .../commons/compress/archivers/tar/TarUtils.java | 199 ++ .../commons/compress/archivers/zip/ZipFile.java| 81 +-- .../compress/utils/BoundedArchiveInputStream.java | 98 +++ .../BoundedSeekableByteChannelInputStream.java | 57 ++ .../commons/compress/archivers/TarTestCase.java| 284 +++- .../commons/compress/archivers/tar/BigFilesIT.java | 78 +-- .../compress/archivers/tar/SparseFilesTest.java| 196 +- .../archivers/tar/TarArchiveEntryTest.java | 34 + .../archivers/tar/TarArchiveInputStreamTest.java | 64 +- .../compress/archivers/tar/TarFileTest.java| 359 ++ .../compress/archivers/tar/TarUtilsTest.java | 71 +- ...BoundedSeekableByteChannelInputStreamTest.java} | 32 +- .../resources/{COMPRESS-529.tar => directory.tar} | Bin 1536 -> 1536 bytes 17 files changed, 2155 insertions(+), 461 deletions(-) copy src/main/java/org/apache/commons/compress/{PasswordRequiredException.java => archivers/tar/TarArchiveSparseZeroInputStream.java} (60%) create mode 100644 src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java create mode 100644 src/main/java/org/apache/commons/compress/utils/BoundedArchiveInputStream.java create mode 100644 src/main/java/org/apache/commons/compress/utils/BoundedSeekableByteChannelInputStream.java create mode 100644 src/test/java/org/apache/commons/compress/archivers/tar/TarFileTest.java copy src/test/java/org/apache/commons/compress/{archivers/zip/X000A_NTFSTest.java => utils/BoundedSeekableByteChannelInputStreamTest.java} (55%) copy src/test/resources/{COMPRESS-529.tar => directory.tar} (58%)
[commons-compress] 02/13: COMPRESS-540: Change visibility of methods moved to TarUtils to protected
This is an automated email from the ASF dual-hosted git repository. peterlee pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git commit f11c897300b6e95c1f0140451f851841adc28fce Author: theobisproject AuthorDate: Fri Jul 24 10:01:06 2020 +0200 COMPRESS-540: Change visibility of methods moved to TarUtils to protected --- .../java/org/apache/commons/compress/archivers/tar/TarUtils.java| 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java index 2e5c30c..e1b87b2 100644 --- a/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java +++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java @@ -660,7 +660,7 @@ public class TarUtils { * @return map of PAX headers values found inside of the current (local or global) PAX headers tar entry. * @throws IOException */ -public static Map parsePaxHeaders(final InputStream inputStream, final List sparseHeaders, final Map globalPaxHeaders) +protected static Map parsePaxHeaders(final InputStream inputStream, final List sparseHeaders, final Map globalPaxHeaders) throws IOException { final Map headers = new HashMap<>(globalPaxHeaders); Long offset = null; @@ -752,7 +752,7 @@ public class TarUtils { * @param sparseMap the sparse map string consisting of comma-separated values "offset,size[,offset-1,size-1...]" * @return sparse headers parsed from sparse map */ -public static List parsePAX01SparseHeaders(String sparseMap) { +protected static List parsePAX01SparseHeaders(String sparseMap) { List sparseHeaders = new ArrayList<>(); String[] sparseHeaderStrings = sparseMap.split(","); @@ -776,7 +776,7 @@ public class TarUtils { * @return sparse headers * @throws IOException */ -public static List parsePAX1XSparseHeaders(final InputStream inputStream, final int recordSize) throws IOException { +protected static List parsePAX1XSparseHeaders(final InputStream inputStream, final int recordSize) throws IOException { // for 1.X PAX Headers List sparseHeaders = new ArrayList<>(); long bytesRead = 0;
[commons-compress] 01/13: COMPRESS-540: Implement TarFile to allow random access to tar files
This is an automated email from the ASF dual-hosted git repository. peterlee pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git commit 81f2084a6b2d44ff455874bbcc1a9dfb14f287d3 Author: theobisproject AuthorDate: Mon Jul 6 15:12:14 2020 +0200 COMPRESS-540: Implement TarFile to allow random access to tar files Basic idea behind the implementation is to read all headers at instantiation and save the position to the entry data. This will then be accessed as a random access file when reading the entry. --- .../compress/archivers/tar/TarArchiveEntry.java| 37 ++ .../archivers/tar/TarArchiveInputStream.java | 229 +-- .../tar/TarArchiveSparseZeroInputStream.java | 49 ++ .../commons/compress/archivers/tar/TarFile.java| 712 + .../commons/compress/archivers/tar/TarUtils.java | 199 ++ .../commons/compress/archivers/zip/ZipFile.java| 81 +-- .../compress/utils/BoundedNIOInputStream.java | 97 +++ .../BoundedSeekableByteChannelInputStream.java | 56 ++ .../commons/compress/archivers/TarTestCase.java| 232 ++- .../commons/compress/archivers/tar/BigFilesIT.java | 78 +-- .../compress/archivers/tar/SparseFilesTest.java| 197 +- .../archivers/tar/TarArchiveInputStreamTest.java | 61 -- .../compress/archivers/tar/TarFileTest.java| 87 +++ .../compress/archivers/tar/TarUtilsTest.java | 71 +- .../BoundedSeekableByteChannelInputStreamTest.java | 41 ++ src/test/resources/directory.tar | Bin 0 -> 1536 bytes 16 files changed, 1798 insertions(+), 429 deletions(-) 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 1f373c4..d4eb2ed 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 @@ -256,6 +256,7 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants { /** Convert millis to seconds */ public static final int MILLIS_PER_SECOND = 1000; +private long dataPosition = -1; /** * Construct an empty entry and prepares the header values. @@ -554,6 +555,23 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants { } /** + * Construct an entry from an archive's header bytes for random access tar. File is set to null. + * @param headerBuf The header bytes from a tar archive entry. + * @param encoding encoding to use for file names + * @param lenient when set to true illegal values for group/userid, mode, device numbers and timestamp will be + * ignored and the fields set to {@link #UNKNOWN}. When set to false such illegal fields cause an exception instead. + * @param dataPosition Position of the entry data in the random access file + * @since 1.21 + * @throws IllegalArgumentException if any of the numeric fields have an invalid format + * @throws IOException on error + */ +public TarArchiveEntry(final byte[] headerBuf, final ZipEncoding encoding, final boolean lenient, +final long dataPosition) throws IOException { +this(headerBuf, encoding, lenient); +this.dataPosition = dataPosition; +} + +/** * Determine if the two entries are equal. Equality is determined * by the header names being equal. * @@ -1185,6 +1203,25 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants { } /** + * Data position of the archive entry in a random access tar + * @return position of the data in the tar file. If the entry is created from a stream and therefore the data + * position is unknown this will return -1. + * @since 1.21 + */ +public long getDataPosition() { +return dataPosition; +} + +/** + * Set the position of the data for the tar entry. + * @param dataPosition the position of the data in the tar + * @since 1.21 + */ +public void setDataPosition(final long dataPosition) { +this.dataPosition = dataPosition; +} + +/** * get extra PAX Headers * @return read-only map containing any extra PAX Headers * @since 1.15 diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java index dd9dba5..3f160dc 100644 --- a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java @@ -27,7 +27,6 @@ import java.io.ByteArrayOutputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import java.nio.charset.StandardCharsets; import java.util.A
[commons-compress] 10/13: COMPRESS-540: Rename BoundedNIOInputStream -> BoundedArchiveInputStream
This is an automated email from the ASF dual-hosted git repository. peterlee pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git commit 53bc2f725b006d54c1b1d94cc2970de818440dea Author: theobisproject AuthorDate: Sat Dec 26 12:56:28 2020 +0100 COMPRESS-540: Rename BoundedNIOInputStream -> BoundedArchiveInputStream --- .../apache/commons/compress/archivers/tar/TarFile.java | 4 ++-- .../apache/commons/compress/archivers/zip/ZipFile.java | 6 +++--- ...InputStream.java => BoundedArchiveInputStream.java} | 18 +- .../utils/BoundedSeekableByteChannelInputStream.java | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java index 664d3ee..dfe5846 100644 --- a/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java +++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java @@ -38,7 +38,7 @@ import org.apache.commons.compress.archivers.zip.ZipEncoding; import org.apache.commons.compress.archivers.zip.ZipEncodingHelper; import org.apache.commons.compress.utils.ArchiveUtils; import org.apache.commons.compress.utils.BoundedInputStream; -import org.apache.commons.compress.utils.BoundedNIOInputStream; +import org.apache.commons.compress.utils.BoundedArchiveInputStream; import org.apache.commons.compress.utils.BoundedSeekableByteChannelInputStream; import org.apache.commons.compress.utils.SeekableInMemoryByteChannel; @@ -644,7 +644,7 @@ public class TarFile implements Closeable { archive.close(); } -private final class BoundedTarEntryInputStream extends BoundedNIOInputStream { +private final class BoundedTarEntryInputStream extends BoundedArchiveInputStream { private final SeekableByteChannel channel; diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java index cd52fe1..1a62ab8 100644 --- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java +++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java @@ -45,7 +45,7 @@ import java.util.zip.ZipException; import org.apache.commons.compress.archivers.EntryStreamOffsets; import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; import org.apache.commons.compress.compressors.deflate64.Deflate64CompressorInputStream; -import org.apache.commons.compress.utils.BoundedNIOInputStream; +import org.apache.commons.compress.utils.BoundedArchiveInputStream; import org.apache.commons.compress.utils.BoundedSeekableByteChannelInputStream; import org.apache.commons.compress.utils.CountingInputStream; import org.apache.commons.compress.utils.IOUtils; @@ -1316,7 +1316,7 @@ public class ZipFile implements Closeable { * Creates new BoundedInputStream, according to implementation of * underlying archive channel. */ -private BoundedNIOInputStream createBoundedInputStream(final long start, final long remaining) { +private BoundedArchiveInputStream createBoundedInputStream(final long start, final long remaining) { return archive instanceof FileChannel ? new BoundedFileChannelInputStream(start, remaining) : new BoundedSeekableByteChannelInputStream(start, remaining, archive); @@ -1328,7 +1328,7 @@ public class ZipFile implements Closeable { * file channel and therefore performs significantly faster in * concurrent environment. */ -private class BoundedFileChannelInputStream extends BoundedNIOInputStream { +private class BoundedFileChannelInputStream extends BoundedArchiveInputStream { private final FileChannel archive; BoundedFileChannelInputStream(final long start, final long remaining) { diff --git a/src/main/java/org/apache/commons/compress/utils/BoundedNIOInputStream.java b/src/main/java/org/apache/commons/compress/utils/BoundedArchiveInputStream.java similarity index 82% rename from src/main/java/org/apache/commons/compress/utils/BoundedNIOInputStream.java rename to src/main/java/org/apache/commons/compress/utils/BoundedArchiveInputStream.java index 2a692c0..db8d948 100644 --- a/src/main/java/org/apache/commons/compress/utils/BoundedNIOInputStream.java +++ b/src/main/java/org/apache/commons/compress/utils/BoundedArchiveInputStream.java @@ -26,7 +26,7 @@ import java.nio.ByteBuffer; * @ThreadSafe this base class is thread safe but implementations must not be. * @since 1.21 */ -public abstract class BoundedNIOInputStream extends InputStream { +public abstract class BoundedArchiveInputStream extends InputStream { private final long end; private ByteBuffer singleByteBuffer; @@ -35,10 +35,10 @@ public abstract class BoundedNIOInputStream extends InputStream { /** * Create a new b
[commons-compress] 03/13: COMPRESS-540: Implement storage of data offset in tar entries via EntryStreamOffsets instead of reinventing it
This is an automated email from the ASF dual-hosted git repository. peterlee pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git commit 9f7c5aa03075bda181a7a06ea47d110665979eb8 Author: theobisproject AuthorDate: Fri Jul 24 10:21:07 2020 +0200 COMPRESS-540: Implement storage of data offset in tar entries via EntryStreamOffsets instead of reinventing it --- .../compress/archivers/tar/TarArchiveEntry.java| 38 +- .../commons/compress/archivers/tar/TarFile.java| 12 +++ 2 files changed, 29 insertions(+), 21 deletions(-) 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 d4eb2ed..37e76c9 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 @@ -40,6 +40,7 @@ import java.util.Set; import java.util.concurrent.TimeUnit; import org.apache.commons.compress.archivers.ArchiveEntry; +import org.apache.commons.compress.archivers.EntryStreamOffsets; import org.apache.commons.compress.archivers.zip.ZipEncoding; import org.apache.commons.compress.utils.ArchiveUtils; import org.apache.commons.compress.utils.IOUtils; @@ -158,8 +159,7 @@ import org.apache.commons.compress.utils.IOUtils; * @NotThreadSafe */ -public class TarArchiveEntry implements ArchiveEntry, TarConstants { - +public class TarArchiveEntry implements ArchiveEntry, TarConstants, EntryStreamOffsets { private static final TarArchiveEntry[] EMPTY_TAR_ARCHIVE_ENTRIES = new TarArchiveEntry[0]; /** @@ -256,7 +256,7 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants { /** Convert millis to seconds */ public static final int MILLIS_PER_SECOND = 1000; -private long dataPosition = -1; +private long dataOffset = EntryStreamOffsets.OFFSET_UNKNOWN; /** * Construct an empty entry and prepares the header values. @@ -560,15 +560,15 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants { * @param encoding encoding to use for file names * @param lenient when set to true illegal values for group/userid, mode, device numbers and timestamp will be * ignored and the fields set to {@link #UNKNOWN}. When set to false such illegal fields cause an exception instead. - * @param dataPosition Position of the entry data in the random access file + * @param dataOffset Position of the entry data in the random access file * @since 1.21 * @throws IllegalArgumentException if any of the numeric fields have an invalid format * @throws IOException on error */ public TarArchiveEntry(final byte[] headerBuf, final ZipEncoding encoding, final boolean lenient, -final long dataPosition) throws IOException { +final long dataOffset) throws IOException { this(headerBuf, encoding, lenient); -this.dataPosition = dataPosition; +this.dataOffset = dataOffset; } /** @@ -1203,22 +1203,30 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants { } /** - * Data position of the archive entry in a random access tar - * @return position of the data in the tar file. If the entry is created from a stream and therefore the data - * position is unknown this will return -1. + * {@inheritDoc} + * @since 1.21 + */ +@Override +public long getDataOffset() { +return dataOffset; +} + +/** + * Set the offset of the data for the tar entry. + * @param dataOffset the position of the data in the tar * @since 1.21 */ -public long getDataPosition() { -return dataPosition; +public void setDataOffset(final long dataOffset) { +this.dataOffset = dataOffset; } /** - * Set the position of the data for the tar entry. - * @param dataPosition the position of the data in the tar + * {@inheritDoc} * @since 1.21 */ -public void setDataPosition(final long dataPosition) { -this.dataPosition = dataPosition; +@Override +public boolean isStreamContiguous() { +return true; } /** diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java index 714ff8a..c33ba2e 100644 --- a/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java +++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java @@ -233,7 +233,7 @@ public class TarFile implements Closeable { if (currEntry != null) { // Skip to the end of the entry -archive.position(currEntry.getDataPosition() + currEntry.getSize()); +archive.position(currEntry.getDataOffset() + currEntry.getSize
[commons-compress] 07/13: COMPRESS-540: Fix problems with long filenames
This is an automated email from the ASF dual-hosted git repository. peterlee pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git commit f0aaab65408f53684efa9fc450819fff51c69436 Author: theobisproject AuthorDate: Fri Nov 13 14:08:27 2020 +0100 COMPRESS-540: Fix problems with long filenames Includes fix for COMPRESS-558 If an archive contains many files with long names or a name which is larger than the buffer until know the name was wrong Add missing tests from TarArchiveInputStreamTest to TarFileTest --- .../commons/compress/archivers/tar/TarFile.java| 16 +- .../commons/compress/archivers/TarTestCase.java| 54 - .../compress/archivers/tar/TarFileTest.java| 233 + 3 files changed, 295 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java index d8e517d..f512d29 100644 --- a/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java +++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java @@ -43,14 +43,14 @@ import org.apache.commons.compress.utils.BoundedSeekableByteChannelInputStream; import org.apache.commons.compress.utils.SeekableInMemoryByteChannel; /** - * The TarFile provides random access to UNIX to archives. + * The TarFile provides random access to UNIX archives. * @since 1.21 */ public class TarFile implements Closeable { private static final int SMALL_BUFFER_SIZE = 256; -private final ByteBuffer smallBuf = ByteBuffer.allocate(SMALL_BUFFER_SIZE); +private final byte[] smallBuf = new byte[SMALL_BUFFER_SIZE]; private final SeekableByteChannel archive; @@ -273,11 +273,11 @@ public class TarFile implements Closeable { } // COMPRESS-509 : the name of directories should end with '/' -String name = zipEncoding.decode(longNameData); +final String name = zipEncoding.decode(longNameData); +currEntry.setName(name); if (currEntry.isDirectory() && !name.endsWith("/")) { -name += "/"; +currEntry.setName(name + "/"); } -currEntry.setName(name); } if (currEntry.isGlobalPaxHeader()) { // Process Global Pax headers @@ -474,8 +474,10 @@ public class TarFile implements Closeable { private byte[] getLongNameData() throws IOException { final ByteArrayOutputStream longName = new ByteArrayOutputStream(); int length; -while ((length = archive.read(smallBuf)) > 0) { -longName.write(smallBuf.array(), 0, length); +try (final InputStream in = getInputStream(currEntry)) { +while ((length = in.read(smallBuf)) >= 0) { +longName.write(smallBuf, 0, length); +} } getNextTarEntry(); if (currEntry == null) { diff --git a/src/test/java/org/apache/commons/compress/archivers/TarTestCase.java b/src/test/java/org/apache/commons/compress/archivers/TarTestCase.java index f5dc104..e4fd699 100644 --- a/src/test/java/org/apache/commons/compress/archivers/TarTestCase.java +++ b/src/test/java/org/apache/commons/compress/archivers/TarTestCase.java @@ -18,14 +18,17 @@ */ package org.apache.commons.compress.archivers; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.util.List; import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.List; import org.apache.commons.compress.AbstractTestCase; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; @@ -534,4 +537,53 @@ public final class TarTestCase extends AbstractTestCase { } } } + +@Test +public void testLongNameLargerThanBuffer() throws IOException { +final List nameLength = Arrays.asList(300, 4096); + +for (final Integer length : nameLength) { +final String fileName = createLongName(length); +assertEquals(length.intValue(), fileName.length()); +final byte[] data = createTarWithOneLongNameEntry(fileName); +try (final ByteArrayInputStream bis = new ByteArrayInputStream(data); + final TarArchiveInputStream tis = new TarArchiveInputStream(bis)) { +assertEquals(fileName, tis.getNextTarEntry().getName()); +} +} +} + +@Test +public void testTarFileLongNameLargerThanBuffer() throws IOException { +final List nameLength = Arrays.asList(300, 4096); + +for (final Integer length : nameLength) { +final String fileNa
[commons-compress] 08/13: COMPRESS-540: Javadoc enhancement
This is an automated email from the ASF dual-hosted git repository. peterlee pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git commit 543ac95593bcad8d656e27be1e2ce2e48cd26b4a Author: theobisproject AuthorDate: Fri Dec 25 21:37:14 2020 +0100 COMPRESS-540: Javadoc enhancement - Add thread safety information for input streams - Use consistent capitalization and punctuation in Javadoc - Use html tags for better Javadoc formatting --- .../commons/compress/archivers/tar/TarArchiveEntry.java | 16 .../apache/commons/compress/archivers/tar/TarFile.java | 14 +- .../commons/compress/utils/BoundedNIOInputStream.java| 1 + .../utils/BoundedSeekableByteChannelInputStream.java | 1 + 4 files changed, 19 insertions(+), 13 deletions(-) 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 37e76c9..9153a5d 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 @@ -556,14 +556,14 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants, EntryStreamO /** * Construct an entry from an archive's header bytes for random access tar. File is set to null. - * @param headerBuf The header bytes from a tar archive entry. - * @param encoding encoding to use for file names + * @param headerBuf the header bytes from a tar archive entry. + * @param encoding encoding to use for file names. * @param lenient when set to true illegal values for group/userid, mode, device numbers and timestamp will be * ignored and the fields set to {@link #UNKNOWN}. When set to false such illegal fields cause an exception instead. - * @param dataOffset Position of the entry data in the random access file + * @param dataOffset position of the entry data in the random access file. * @since 1.21 - * @throws IllegalArgumentException if any of the numeric fields have an invalid format - * @throws IOException on error + * @throws IllegalArgumentException if any of the numeric fields have an invalid format. + * @throws IOException on error. */ public TarArchiveEntry(final byte[] headerBuf, final ZipEncoding encoding, final boolean lenient, final long dataOffset) throws IOException { @@ -869,7 +869,7 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants, EntryStreamO * This method is only useful for entries created from a {@code * File} or {@code Path} but not for entries read from an archive. * - * @return This entry's file or null if the entry was not created from a file. + * @return this entry's file or null if the entry was not created from a file. */ public File getFile() { if (file == null) { @@ -884,7 +884,7 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants, EntryStreamO * This method is only useful for entries created from a {@code * File} or {@code Path} but not for entries read from an archive. * - * @return This entry's file or null if the entry was not created from a file. + * @return this entry's file or null if the entry was not created from a file. * @since 1.21 */ public Path getPath() { @@ -1213,7 +1213,7 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants, EntryStreamO /** * Set the offset of the data for the tar entry. - * @param dataOffset the position of the data in the tar + * @param dataOffset the position of the data in the tar. * @since 1.21 */ public void setDataOffset(final long dataOffset) { diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java index f512d29..dc4ab20 100644 --- a/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java +++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java @@ -332,7 +332,7 @@ public class TarFile implements Closeable { * When reading from the non-zero input streams, the data is actually read from the original input stream. * The size of each input stream is introduced by the sparse headers. * - * NOTE : Some all-zero input streams and non-zero input streams have the size of 0. We DO NOT store the + * @implNote Some all-zero input streams and non-zero input streams have the size of 0. We DO NOT store the *0 size input streams because they are meaningless. */ private void buildSparseInputStreams() throws IOException { @@ -398,24 +398,28 @@ public class TarFile implements Closeable { } /** + * * For PAX Forma
[commons-compress] 13/13: COMPRESS-540: Tar entry offset should not be smaller than 0
This is an automated email from the ASF dual-hosted git repository. peterlee pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git commit f36fe7e9715e063f500231d8cccae7cfef4f42e6 Author: theobisproject AuthorDate: Mon Jan 4 16:53:58 2021 +0100 COMPRESS-540: Tar entry offset should not be smaller than 0 --- .../compress/archivers/tar/TarArchiveEntry.java| 5 +++- .../archivers/tar/TarArchiveEntryTest.java | 34 ++ 2 files changed, 38 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 9153a5d..54592c3 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 @@ -568,7 +568,7 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants, EntryStreamO public TarArchiveEntry(final byte[] headerBuf, final ZipEncoding encoding, final boolean lenient, final long dataOffset) throws IOException { this(headerBuf, encoding, lenient); -this.dataOffset = dataOffset; +setDataOffset(dataOffset); } /** @@ -1217,6 +1217,9 @@ public class TarArchiveEntry implements ArchiveEntry, TarConstants, EntryStreamO * @since 1.21 */ public void setDataOffset(final long dataOffset) { +if (dataOffset < 0) { +throw new IllegalArgumentException("The offset can not be smaller than 0"); +} this.dataOffset = dataOffset; } diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java index 688afa3..9a95599 100644 --- a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java @@ -34,8 +34,12 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.Locale; import org.apache.commons.compress.AbstractTestCase; +import org.apache.commons.compress.archivers.zip.ZipEncoding; +import org.apache.commons.compress.archivers.zip.ZipEncodingHelper; +import org.apache.commons.compress.utils.CharsetNames; import org.junit.Test; public class TarArchiveEntryTest implements TarConstants { @@ -239,6 +243,36 @@ public class TarArchiveEntryTest implements TarConstants { assertNotEquals("", entry.getUserName()); } +@Test(expected = IllegalArgumentException.class) +public void negativeOffsetInConstructorNotAllowed() throws IOException { +byte[] entryContent = ("test1.xml\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u" + +"\u" + + "\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u" + + "\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u" + + "\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u644\u765\u765" + +"\u0001142\u10716545626\u012260\u 0\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u" + + "\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u" + + "\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u" + + "\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u" + +"\u\u\u\u\u\u\u\u\uustar " + + "\utcurdt\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u" + + "\u\u\utcurdt\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u" + + "\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u\u
[commons-compress] 06/13: COMPRESS-540: Include fix for COMPRESS-553
This is an automated email from the ASF dual-hosted git repository. peterlee pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git commit 6270ff564f88804757d859cd4fb1b989df1021d9 Author: theobisproject AuthorDate: Sat Oct 10 17:21:36 2020 +0200 COMPRESS-540: Include fix for COMPRESS-553 --- .../java/org/apache/commons/compress/archivers/tar/TarUtils.java | 2 +- .../java/org/apache/commons/compress/archivers/tar/TarFileTest.java | 5 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java index e1b87b2..c62b2a6 100644 --- a/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java +++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java @@ -682,7 +682,7 @@ public class TarUtils { final String keyword = coll.toString(CharsetNames.UTF_8); // Get rest of entry final int restLen = len - read; -if (restLen == 1) { // only NL +if (restLen <= 1) { // only NL headers.remove(keyword); } else { final byte[] rest = new byte[restLen]; 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 feccaf1..d953417 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 @@ -102,4 +102,9 @@ public class TarFileTest extends AbstractTestCase { } } +@Test(expected = IOException.class) +public void testThrowException() throws IOException { +try (TarFile tarFile = new TarFile(getPath("COMPRESS-553.tar"))) { +} +} }
[commons-compress] 11/13: COMPRESS-540: Include changes from COMPRESS-559
This is an automated email from the ASF dual-hosted git repository. peterlee pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git commit 20f8b3e7292a6571b34690b1b408e93e0b81b42b Author: theobisproject AuthorDate: Tue Dec 29 22:38:13 2020 +0100 COMPRESS-540: Include changes from COMPRESS-559 --- .../apache/commons/compress/archivers/tar/SparseFilesTest.java | 9 ++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java index 436b5a8..a095157 100644 --- a/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java @@ -368,6 +368,11 @@ public class SparseFilesTest extends AbstractTestCase { @Test public void testTarFileExtractPaxGNU() throws IOException, InterruptedException { Assume.assumeFalse("Don't run test on Windows", isOnWindows); +// GNU tar with version 1.28 has some problems reading sparsefile-0.1, +// so the test should be skipped then +// TODO : what about the versions lower than 1.28? +assumeFalse("This test should be ignored if GNU tar is version 1.28", +getTarBinaryHelp().startsWith("tar (GNU tar) 1.28")); final File file = getFile("pax_gnu_sparse.tar"); try (final TarFile paxGnu = new TarFile(file)) { @@ -379,10 +384,8 @@ public class SparseFilesTest extends AbstractTestCase { assertArrayEquals(IOUtils.toByteArray(paxInput), IOUtils.toByteArray(sparseFileInputStream)); } -// TODO : it's wired that I can only get a 0 size sparsefile-0.1 on my Ubuntu 16.04 -//using "tar -xf pax_gnu_sparse.tar" entry = entries.get(1); -try (InputStream sparseFileInputStream = extractTarAndGetInputStream(file, "sparsefile-0.0"); +try (InputStream sparseFileInputStream = extractTarAndGetInputStream(file, "sparsefile-0.1"); InputStream paxInput = paxGnu.getInputStream(entry)) { assertArrayEquals(IOUtils.toByteArray(paxInput), IOUtils.toByteArray(sparseFileInputStream)); }
[commons-compress] 04/13: COMPRESS-540: Include fix for COMPRESS-544
This is an automated email from the ASF dual-hosted git repository. peterlee pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git commit 57e2b28baddbd4c7abb4be590d7d9d7ecaf9e54f Author: theobisproject AuthorDate: Sun Aug 30 14:07:43 2020 +0200 COMPRESS-540: Include fix for COMPRESS-544 --- .../org/apache/commons/compress/archivers/tar/TarFile.java | 12 .../apache/commons/compress/archivers/tar/TarFileTest.java | 12 2 files changed, 24 insertions(+) diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java index c33ba2e..41e3db8 100644 --- a/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java +++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java @@ -234,6 +234,7 @@ public class TarFile implements Closeable { if (currEntry != null) { // Skip to the end of the entry archive.position(currEntry.getDataOffset() + currEntry.getSize()); +throwExceptionIfPositionIsNotInArchive(); skipRecordPadding(); } @@ -501,6 +502,17 @@ public class TarFile implements Closeable { final long numRecords = (currEntry.getSize() / recordSize) + 1; final long padding = (numRecords * recordSize) - currEntry.getSize(); archive.position(archive.position() + padding); +throwExceptionIfPositionIsNotInArchive(); +} +} + +/** + * Checks if the current position of the SeekableByteChannel is in the archive. + * @throws IOException If the position is not in the archive + */ +private void throwExceptionIfPositionIsNotInArchive() throws IOException { +if (archive.size() < archive.position()) { +throw new IOException("Truncated TAR archive"); } } 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 a453d3b..778d959 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 @@ -84,4 +84,16 @@ public class TarFileTest extends AbstractTestCase { } } +@Test(expected = IOException.class) +public void testParseTarTruncatedInPadding() throws IOException { +try (TarFile tarFile = new TarFile(getPath("COMPRESS-544_truncated_in_padding.tar"))) { +} +} + +@Test(expected = IOException.class) +public void testParseTarTruncatedInContent() throws IOException { +try (TarFile tarFile = new TarFile(getPath("COMPRESS-544_truncated_in_content.tar"))) { +} +} + }
[commons-compress] 12/13: COMPRESS-540: Remove commented out code in test
This is an automated email from the ASF dual-hosted git repository. peterlee pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git commit 34759ba88f8121e5ac4332c4b2150e758e27cbb2 Author: theobisproject AuthorDate: Wed Dec 30 17:26:06 2020 +0100 COMPRESS-540: Remove commented out code in test --- .../org/apache/commons/compress/archivers/tar/SparseFilesTest.java| 4 1 file changed, 4 deletions(-) diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java index a095157..5f9b14b 100644 --- a/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java @@ -79,8 +79,6 @@ public class SparseFilesTest extends AbstractTestCase { assertTrue(ae.isOldGNUSparse()); assertTrue(ae.isGNUSparse()); assertFalse(ae.isPaxGNUSparse()); -// TODO: Is this something which should be supported in the random access implementation. Is this even needed in the current stream implementation as it supports sparse entries now? -//assertFalse(tin.canReadEntryData(ae)); List sparseHeaders = ae.getSparseHeaders(); assertEquals(3, sparseHeaders.size()); @@ -122,8 +120,6 @@ public class SparseFilesTest extends AbstractTestCase { assertTrue(entry.isGNUSparse()); assertTrue(entry.isPaxGNUSparse()); assertFalse(entry.isOldGNUSparse()); -// TODO: Is this something which should be supported in the random access implementation. Is this even needed in the current stream implementation as it supports sparse entries now? -//assertFalse(tin.canReadEntryData(entry)); List sparseHeaders = entry.getSparseHeaders(); assertEquals(3, sparseHeaders.size());
[commons-compress] 05/13: COMPRESS-540: Include fix for COMPRESS-554
This is an automated email from the ASF dual-hosted git repository. peterlee pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git commit 3b7f0aedf936792903bd721edb59418b057091bc Author: theobisproject AuthorDate: Thu Sep 3 19:05:11 2020 +0200 COMPRESS-540: Include fix for COMPRESS-554 This revealed the missing reset of the current entry if the header is not present and the usage of the wrong entry in the stream. --- .../java/org/apache/commons/compress/archivers/tar/TarFile.java | 8 +++- .../org/apache/commons/compress/archivers/tar/TarFileTest.java| 6 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java index 41e3db8..d8e517d 100644 --- a/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java +++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java @@ -241,6 +241,8 @@ public class TarFile implements Closeable { final ByteBuffer headerBuf = getRecord(); if (null == headerBuf) { +/* hit EOF */ +currEntry = null; return null; } @@ -457,6 +459,10 @@ public class TarFile implements Closeable { globalPaxHeaders = TarUtils.parsePaxHeaders(input, globalSparseHeaders, globalPaxHeaders); } getNextTarEntry(); // Get the actual file entry + +if (currEntry == null) { +throw new IOException("Error detected parsing the pax header"); +} } /** @@ -641,7 +647,7 @@ public class TarFile implements Closeable { protected int read(final long pos, final ByteBuffer buf) throws IOException { if (entry.isSparse()) { // for sparse entries, there are actually currEntry.getRealSize() bytes to read -if (entryOffset >= currEntry.getRealSize()) { +if (entryOffset >= entry.getRealSize()) { return -1; } } else { 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 778d959..feccaf1 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 @@ -96,4 +96,10 @@ public class TarFileTest extends AbstractTestCase { } } +@Test(expected = IOException.class) +public void testThrowExceptionWithNullEntry() throws IOException { +try (TarFile tarFile = new TarFile(getPath("COMPRESS-554.tar"))) { +} +} + }
[commons-compress] branch master updated: document COMPRESS-540
This is an automated email from the ASF dual-hosted git repository. peterlee 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 46b652c document COMPRESS-540 46b652c is described below commit 46b652c36e28f10b7a373190235370801f10288f Author: PeterAlfredLee AuthorDate: Sat Jan 9 11:27:49 2021 +0800 document COMPRESS-540 --- src/changes/changes.xml | 5 + 1 file changed, 5 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 21907b9..bedb376 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -291,6 +291,11 @@ The type attribute can be add,update,fix,remove. Bump zstd-jni from 1.4.5-12 to 1.4.8-1 #159. + +Added support for random access to the TAR packages. +Github Pull Request #113. +
[commons-compress] branch master updated: use final
This is an automated email from the ASF dual-hosted git repository. peterlee 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 221b2ba use final 221b2ba is described below commit 221b2badbe2c09f88892aeb6627b74afe6f46851 Author: PeterAlfredLee AuthorDate: Thu Feb 4 20:59:34 2021 +0800 use final --- .../apache/commons/compress/archivers/tar/TarFile.java | 16 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java index dfe5846..8e39d0f 100644 --- a/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java +++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java @@ -336,7 +336,7 @@ public class TarFile implements Closeable { *0 size input streams because they are meaningless. */ private void buildSparseInputStreams() throws IOException { -List streams = new ArrayList<>(); +final List streams = new ArrayList<>(); final List sparseHeaders = currEntry.getSparseHeaders(); // sort the sparse headers in case they are written in wrong order @@ -368,14 +368,14 @@ public class TarFile implements Closeable { // only store the input streams with non-zero size if ((sparseHeader.getOffset() - offset) > 0) { -long sizeOfZeroByteStream = sparseHeader.getOffset() - offset; +final long sizeOfZeroByteStream = sparseHeader.getOffset() - offset; streams.add(new BoundedInputStream(zeroInputStream, sizeOfZeroByteStream)); numberOfZeroBytesInSparseEntry += sizeOfZeroByteStream; } // only store the input streams with non-zero size if (sparseHeader.getNumbytes() > 0) { -long start = +final long start = currEntry.getDataOffset() + sparseHeader.getOffset() - numberOfZeroBytesInSparseEntry; streams.add(new BoundedSeekableByteChannelInputStream(start, sparseHeader.getNumbytes(), archive)); } @@ -673,7 +673,7 @@ public class TarFile implements Closeable { } } -int totalRead = 0; +final int totalRead; if (entry.isSparse()) { totalRead = readSparse(entryOffset, buf, buf.limit()); } else { @@ -703,8 +703,8 @@ public class TarFile implements Closeable { } final InputStream currentInputStream = entrySparseInputStreams.get(currentSparseInputStreamIndex); -byte[] bufArray = new byte[numToRead]; -int readLen = currentInputStream.read(bufArray); +final byte[] bufArray = new byte[numToRead]; +final int readLen = currentInputStream.read(bufArray); if (readLen != -1) { buf.put(bufArray, 0, readLen); } @@ -725,7 +725,7 @@ public class TarFile implements Closeable { // and recursively call read if (readLen < numToRead) { currentSparseInputStreamIndex++; -int readLenOfNext = readSparse(pos + readLen, buf, numToRead - readLen); +final int readLenOfNext = readSparse(pos + readLen, buf, numToRead - readLen); if (readLenOfNext == -1) { return readLen; } @@ -739,7 +739,7 @@ public class TarFile implements Closeable { private int readArchive(final long pos, final ByteBuffer buf) throws IOException { channel.position(pos); -int read = channel.read(buf); +final int read = channel.read(buf); buf.flip(); return read; }
[commons-compress] branch master updated: OMPRESS-565 : add BufferPool support in zstd
This is an automated email from the ASF dual-hosted git repository. peterlee 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 04ed3f1 OMPRESS-565 : add BufferPool support in zstd 04ed3f1 is described below commit 04ed3f17af88ec3910d8d62c6a42fcfffb894d25 Author: PeterAlfredLee AuthorDate: Wed Feb 10 09:17:46 2021 +0800 OMPRESS-565 : add BufferPool support in zstd add BufferPool as a configuration in ZstdCompressorInputStream --- .../zstandard/ZstdCompressorInputStream.java | 17 ++ .../zstandard/ZstdCompressorInputStreamTest.java | 36 ++ 2 files changed, 53 insertions(+) diff --git a/src/main/java/org/apache/commons/compress/compressors/zstandard/ZstdCompressorInputStream.java b/src/main/java/org/apache/commons/compress/compressors/zstandard/ZstdCompressorInputStream.java index 7b23794..6361dac 100644 --- a/src/main/java/org/apache/commons/compress/compressors/zstandard/ZstdCompressorInputStream.java +++ b/src/main/java/org/apache/commons/compress/compressors/zstandard/ZstdCompressorInputStream.java @@ -21,6 +21,7 @@ package org.apache.commons.compress.compressors.zstandard; import java.io.IOException; import java.io.InputStream; +import com.github.luben.zstd.BufferPool; import com.github.luben.zstd.ZstdInputStream; import org.apache.commons.compress.compressors.CompressorInputStream; import org.apache.commons.compress.utils.CountingInputStream; @@ -43,6 +44,22 @@ public class ZstdCompressorInputStream extends CompressorInputStream this.decIS = new ZstdInputStream(countingStream = new CountingInputStream(in)); } +/** + * Creates a new input stream that decompresses zstd-compressed data from + * the specific input stream + * + * @param in the input stream of compressed data + * @param bufferPool a configuration of zstd-jni that allows users to customize + * how buffers are recycled. Either a + * {@link com.github.luben.zstd.NoPool} or a + * {@link com.github.luben.zstd.RecyclingBufferPool} is + * allowed here. + * @throws IOException if an IO error occurs. + */ +public ZstdCompressorInputStream(final InputStream in, final BufferPool bufferPool) throws IOException { +this.decIS = new ZstdInputStream(countingStream = new CountingInputStream(in), bufferPool); +} + @Override public int available() throws IOException { return decIS.available(); diff --git a/src/test/java/org/apache/commons/compress/compressors/zstandard/ZstdCompressorInputStreamTest.java b/src/test/java/org/apache/commons/compress/compressors/zstandard/ZstdCompressorInputStreamTest.java index 4bedd3b..728f9aa 100644 --- a/src/test/java/org/apache/commons/compress/compressors/zstandard/ZstdCompressorInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/compressors/zstandard/ZstdCompressorInputStreamTest.java @@ -27,6 +27,8 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import com.github.luben.zstd.NoPool; +import com.github.luben.zstd.RecyclingBufferPool; import org.apache.commons.compress.AbstractTestCase; import org.apache.commons.compress.compressors.CompressorInputStream; import org.apache.commons.compress.compressors.CompressorStreamFactory; @@ -59,6 +61,40 @@ public class ZstdCompressorInputStreamTest extends AbstractTestCase { } @Test +public void testZstdDecodeWithNoPool() throws IOException { +final File input = getFile("zstandard.testdata.zst"); +final File expected = getFile("zstandard.testdata"); +try (InputStream inputStream = new FileInputStream(input); + ZstdCompressorInputStream zstdInputStream = new ZstdCompressorInputStream(inputStream, NoPool.INSTANCE)) { +final byte[] b = new byte[97]; +IOUtils.read(expected, b); +final ByteArrayOutputStream bos = new ByteArrayOutputStream(); +int readByte = -1; +while((readByte = zstdInputStream.read()) != -1) { +bos.write(readByte); +} +Assert.assertArrayEquals(b, bos.toByteArray()); +} +} + +@Test +public void testZstdDecodeWithRecyclingBufferPool() throws IOException { +final File input = getFile("zstandard.testdata.zst"); +final File expected = getFile("zstandard.testdata"); +try (InputStream inputStream = new FileInputStream(input); + ZstdCompressorInputStream zstdInputStream = new ZstdCompressorInputStream(inputStream, RecyclingBufferPool.INSTANCE)) { +final byte[] b = new byte[97]; +IOUtils.read(expected, b); +final ByteArrayOutputStream bos = new ByteArrayO
[commons-compress] branch master updated: document COMPRESS-565 with PR#165
This is an automated email from the ASF dual-hosted git repository. peterlee 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 77db855 document COMPRESS-565 with PR#165 77db855 is described below commit 77db855c7c7e3ad0ef570058f312f0559af53901 Author: PeterAlfredLee AuthorDate: Sun Feb 14 18:23:26 2021 +0800 document COMPRESS-565 with PR#165 --- src/changes/changes.xml | 5 + 1 file changed, 5 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index c019cf0..f5b7bc0 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -296,6 +296,11 @@ The type attribute can be add,update,fix,remove. Added support for random access to the TAR packages. Github Pull Request #113. + +Added support for BufferPool in ZstdCompressorInputStream. +Github Pull Request #165. +
[commons-compress] branch master updated: COMPRESS-571 : SevenZFile.getEntries now return a copy of entries
This is an automated email from the ASF dual-hosted git repository. peterlee 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 65a5c75 COMPRESS-571 : SevenZFile.getEntries now return a copy of entries 65a5c75 is described below commit 65a5c75c015e332adf99ef033311b2642b106c38 Author: PeterAlfredLee AuthorDate: Wed Mar 17 16:00:39 2021 +0800 COMPRESS-571 : SevenZFile.getEntries now return a copy of entries --- src/changes/changes.xml | 3 +++ .../apache/commons/compress/archivers/sevenz/SevenZFile.java | 6 +++--- .../commons/compress/archivers/sevenz/SevenZFileTest.java| 12 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 6337843..505cb61 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -329,6 +329,9 @@ The type attribute can be add,update,fix,remove. xz/brotli/zstd/lzma have been available even in OSGi environments. + +SevenZFile.getEntries now return a copy of entries. + diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java index ba6e719..80d2f8a 100644 --- a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java +++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java @@ -414,7 +414,7 @@ public class SevenZFile implements Closeable { } /** - * Returns meta-data of all archive entries. + * Returns a copy of meta-data of all archive entries. * * This method only provides meta-data, the entries can not be * used to read the contents, you still need to process all @@ -423,11 +423,11 @@ public class SevenZFile implements Closeable { * The content methods are only available for entries that have * already been reached via {@link #getNextEntry}. * - * @return meta-data of all archive entries. + * @return a copy of meta-data of all archive entries. * @since 1.11 */ public Iterable getEntries() { -return Arrays.asList(archive.files); +return new ArrayList<>(Arrays.asList(archive.files)); } private Archive readHeaders(final byte[] password) throws IOException { diff --git a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java index 9e17159..372a743 100644 --- a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java @@ -37,6 +37,7 @@ import java.nio.file.Path; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -734,6 +735,17 @@ public class SevenZFileTest extends AbstractTestCase { } } +@Test +public void retrieveInputStreamForShuffledEntries() throws IOException { +try (final SevenZFile sevenZFile = new SevenZFile(getFile("COMPRESS-348.7z"))) { +List entries = (List) sevenZFile.getEntries(); +Collections.shuffle(entries); +for (final SevenZArchiveEntry entry : entries) { +IOUtils.toByteArray(sevenZFile.getInputStream(entry)); +} +} +} + private void test7zUnarchive(final File f, final SevenZMethod m, final byte[] password) throws Exception { try (SevenZFile sevenZFile = new SevenZFile(f, password)) { test7zUnarchive(sevenZFile, m);
[commons-compress] branch master updated (f387340 -> e03b8d4)
This is an automated email from the ASF dual-hosted git repository. peterlee pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git. from f387340 Replace GitHub build for Java 15 with Java 16 and drop Java 16-ea. add e03b8d4 Bump zstd-jni from 1.4.8-7 to 1.4.9-1 No new revisions were added by this update. Summary of changes: pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
[commons-compress] branch master updated: record #176
This is an automated email from the ASF dual-hosted git repository. peterlee 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 a669dfb record #176 a669dfb is described below commit a669dfb03576e5dd68e105ba86b1fcab90594b1e Author: PeterAlfredLee AuthorDate: Sat Mar 20 11:00:17 2021 +0800 record #176 --- src/changes/changes.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 505cb61..8fa50ab 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -332,6 +332,9 @@ The type attribute can be add,update,fix,remove. SevenZFile.getEntries now return a copy of entries. + +Update com.github.luben:zstd-jni from 1.4.8-7 to 1.4.9-1 #176. +
[commons-compress] branch master updated: * Remove redundant initializer * Remove not use return value
This is an automated email from the ASF dual-hosted git repository. peterlee 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 33789f6 * Remove redundant initializer * Remove not use return value 33789f6 is described below commit 33789f6aa82c7e0576ea918611a484ba410ba08c Author: Arturo Bernal AuthorDate: Fri Mar 26 18:41:05 2021 +0100 * Remove redundant initializer * Remove not use return value --- .../compress/archivers/ArchiveInputStream.java | 2 +- .../compress/archivers/ArchiveOutputStream.java| 2 +- .../archivers/ar/ArArchiveInputStream.java | 6 +++--- .../archivers/ar/ArArchiveOutputStream.java| 12 +-- .../archivers/arj/ArjArchiveInputStream.java | 4 ++-- .../compress/archivers/arj/LocalFileHeader.java| 2 +- .../commons/compress/archivers/arj/MainHeader.java | 2 +- .../compress/archivers/cpio/CpioArchiveEntry.java | 24 +++--- .../archivers/cpio/CpioArchiveInputStream.java | 8 .../archivers/cpio/CpioArchiveOutputStream.java| 4 ++-- .../compress/archivers/dump/TapeInputStream.java | 4 ++-- .../archivers/jar/JarArchiveOutputStream.java | 2 +- .../archivers/sevenz/AES256SHA256Decoder.java | 4 ++-- .../commons/compress/archivers/sevenz/Coder.java | 2 +- .../compress/archivers/sevenz/SevenZFile.java | 2 +- .../archivers/sevenz/SevenZOutputFile.java | 6 +++--- .../compress/archivers/tar/TarArchiveEntry.java| 12 +-- .../archivers/tar/TarArchiveOutputStream.java | 8 .../compress/archivers/zip/AsiExtraField.java | 8 .../archivers/zip/ExplodingInputStream.java| 4 ++-- .../compress/archivers/zip/GeneralPurposeBit.java | 8 .../zip/InflaterInputStreamWithStatistics.java | 4 ++-- .../archivers/zip/ParallelScatterZipCreator.java | 2 +- .../archivers/zip/ResourceAlignmentExtraField.java | 2 +- .../archivers/zip/ScatterZipOutputStream.java | 2 +- .../compress/archivers/zip/StreamCompressor.java | 6 +++--- .../compress/archivers/zip/ZipArchiveEntry.java| 14 ++--- .../archivers/zip/ZipArchiveInputStream.java | 16 +++ .../archivers/zip/ZipArchiveOutputStream.java | 24 +++--- .../archivers/zip/ZipSplitOutputStream.java| 10 - .../compressors/CompressorInputStream.java | 2 +- .../compressors/CompressorStreamFactory.java | 2 +- .../bzip2/BZip2CompressorOutputStream.java | 2 +- .../compressors/deflate64/HuffmanDecoder.java | 8 .../gzip/GzipCompressorInputStream.java| 2 +- .../lz4/BlockLZ4CompressorOutputStream.java| 2 +- .../lz4/FramedLZ4CompressorOutputStream.java | 4 ++-- .../AbstractLZ77CompressorInputStream.java | 2 +- .../compressors/lz77support/LZ77Compressor.java| 10 - .../pack200/Pack200CompressorOutputStream.java | 2 +- .../snappy/FramedSnappyCompressorOutputStream.java | 2 +- .../snappy/SnappyCompressorInputStream.java| 2 +- .../snappy/SnappyCompressorOutputStream.java | 2 +- .../compressors/z/ZCompressorInputStream.java | 2 +- .../commons/compress/utils/BitInputStream.java | 4 ++-- .../compress/utils/CountingOutputStream.java | 2 +- 46 files changed, 126 insertions(+), 130 deletions(-) diff --git a/src/main/java/org/apache/commons/compress/archivers/ArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/ArchiveInputStream.java index 9c4e978..2f03a45 100644 --- a/src/main/java/org/apache/commons/compress/archivers/ArchiveInputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/ArchiveInputStream.java @@ -43,7 +43,7 @@ public abstract class ArchiveInputStream extends InputStream { private static final int BYTE_MASK = 0xFF; /** holds the number of bytes read in this stream */ -private long bytesRead = 0; +private long bytesRead; /** * Returns the next Archive Entry in this Stream. diff --git a/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java b/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java index deadde5..a686c46 100644 --- a/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java @@ -53,7 +53,7 @@ public abstract class ArchiveOutputStream extends OutputStream { static final int BYTE_MASK = 0xFF; /** holds the number of bytes written to this stream */ -private long bytesWritten = 0; +private long bytesWritten; // Methods specific to ArchiveOutputStream /** diff --git a/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java b/src/main/java