You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by bo...@apache.org on 2019/08/09 15:25:11 UTC
[commons-compress] branch COMPRESS-479 updated (378316f -> f3f57dc)
This is an automated email from the ASF dual-hosted git repository.
bodewig pushed a change to branch COMPRESS-479
in repository https://gitbox.apache.org/repos/asf/commons-compress.git.
discard 378316f COMPRESS-479 allow zip extra fields to be degraded to unknown on parser errors
add a016110 Update NOTICE file for 2019.
add e7f79a8 Removed a redundant test in ExplodingInputStream
add f4a190f Harmonized the exception thrown on zip entries using an unsupported compression method in ZipFile and ZipArchiveInputStream
add 31195ff Capitalized the first word of the exception messages
add 98d393d Javadoc: Use "file system" instead of "filesystem".
add ead6fd6 Camel-case name.
add 1b3f112 Javadoc: Use "file name" instead of "filename". Camel case vars "filename" to "fileName".
add 4ff3be9 Name "Apache Commons" in page title.
add 67c6e18 (doc) Fix minor typo from example
add 1e9c8fd Merge pull request #80 from robin850/fix-typo
add f925a0c Performance Improvement: Call toArray with 0 Array Size
add e912631 Merge pull request #81 from DaGeRe/master
add 922b4e0 Fix the site's source repository link.
add 38342b8 COMPRESS-485 keep zip entries order in parallel zip creation
add 4a10122 COMPRESS-485 record change
add 911e4a5 try to get our JDK zoo working in Travis
add b0777e8 add openjdk13 to travis builds
add e217582 Substituting 'synchronized' with faster and fully thread-safe collections 'ConcurrentLinkedDeque' and iterators.
add c5039b5 COMPRESS-485 record second part
add b2026d3 COMPRESS-488 add "cannot skip over prefix" to the list of limitations
add 1f4ae17 be more precise when describing the problem
add 5836405 COMPRESS-490 throw IOException for certain malformed archives
add 6635661 COMPRESS-490 add unit tests, thanks to Alex Rebert
add d503083 not really COMPRESS-490 - throw on negative sizes read from stream
add 317bd05 Gary says exception messages should start with a capitalized word
add 91c2f0d COMPRESS-486 deal with resouce leaks in example code
add 1a14a23 COMPRESS-486 improve documentation
new f3f57dc COMPRESS-479 allow zip extra fields to be degraded to unknown on parser errors
This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version. This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:
* -- * -- B -- O -- O -- O (378316f)
\
N -- N -- N refs/heads/COMPRESS-479 (f3f57dc)
You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.
Any revisions marked "omit" are not gone; other references still
refer to them. Any revisions marked "discard" are gone forever.
The 1 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:
.travis.yml | 34 ++++--
NOTICE.txt | 2 +-
src/changes/changes.xml | 20 +++-
.../archivers/ar/ArArchiveInputStream.java | 20 ++--
.../archivers/ar/ArArchiveOutputStream.java | 14 +--
.../archivers/arj/ArjArchiveInputStream.java | 2 +-
.../compress/archivers/cpio/CpioArchiveEntry.java | 12 +-
.../archivers/cpio/CpioArchiveInputStream.java | 4 +-
.../archivers/cpio/CpioArchiveOutputStream.java | 12 +-
.../compress/archivers/dump/DumpArchiveEntry.java | 8 +-
.../archivers/dump/DumpArchiveInputStream.java | 2 +-
.../archivers/dump/DumpArchiveSummary.java | 6 +-
.../compress/archivers/dump/TapeInputStream.java | 10 +-
.../compress/archivers/examples/Archiver.java | 86 ++++++++++++--
.../archivers/examples/CloseableConsumer.java | 58 ++++++++++
.../examples/CloseableConsumerAdapter.java} | 31 +++---
.../compress/archivers/examples/Expander.java | 124 +++++++++++++++++++--
.../commons/compress/archivers/sevenz/CLI.java | 2 +-
.../compress/archivers/sevenz/CoderBase.java | 2 +-
.../compress/archivers/sevenz/SevenZFile.java | 76 ++++++-------
.../archivers/sevenz/SevenZOutputFile.java | 8 +-
.../archivers/tar/TarArchiveOutputStream.java | 6 +-
.../archivers/zip/AbstractUnicodeExtraField.java | 12 +-
.../compress/archivers/zip/AsiExtraField.java | 6 +-
.../archivers/zip/ExplodingInputStream.java | 2 +-
.../compress/archivers/zip/ExtraFieldUtils.java | 4 +-
.../compress/archivers/zip/GeneralPurposeBit.java | 2 +-
.../archivers/zip/ParallelScatterZipCreator.java | 63 +++++------
.../archivers/zip/ScatterZipOutputStream.java | 42 +++++++
.../archivers/zip/UnicodePathExtraField.java | 4 +-
.../commons/compress/archivers/zip/UnixStat.java | 2 +-
.../zip/UnsupportedZipFeatureException.java | 8 +-
.../zip/Zip64ExtendedInformationExtraField.java | 2 +-
.../archivers/zip/Zip64RequiredException.java | 4 +-
.../compress/archivers/zip/ZipArchiveEntry.java | 6 +-
.../archivers/zip/ZipArchiveInputStream.java | 2 +-
.../archivers/zip/ZipArchiveOutputStream.java | 22 ++--
.../compress/archivers/zip/ZipEncoding.java | 10 +-
.../compress/archivers/zip/ZipEncodingHelper.java | 2 +-
.../commons/compress/archivers/zip/ZipFile.java | 19 ++--
.../apache/commons/compress/changes/Change.java | 10 +-
.../apache/commons/compress/changes/ChangeSet.java | 10 +-
.../commons/compress/changes/ChangeSetResults.java | 24 ++--
.../commons/compress/compressors/FileNameUtil.java | 48 ++++----
.../bzip2/BZip2CompressorInputStream.java | 14 +--
.../bzip2/BZip2CompressorOutputStream.java | 4 +-
.../compress/compressors/bzip2/BZip2Utils.java | 30 ++---
.../gzip/GzipCompressorOutputStream.java | 2 +-
.../compress/compressors/gzip/GzipParameters.java | 12 +-
.../compress/compressors/gzip/GzipUtils.java | 30 ++---
.../lz4/BlockLZ4CompressorInputStream.java | 12 +-
.../lz4/BlockLZ4CompressorOutputStream.java | 2 +-
.../lz4/FramedLZ4CompressorInputStream.java | 10 +-
.../AbstractLZ77CompressorInputStream.java | 30 ++++-
.../compressors/lz77support/LZ77Compressor.java | 2 +-
.../compress/compressors/lzma/LZMAUtils.java | 28 ++---
.../compress/compressors/lzw/LZWInputStream.java | 2 +-
.../snappy/FramedSnappyCompressorInputStream.java | 21 +++-
.../snappy/SnappyCompressorInputStream.java | 31 +++++-
.../commons/compress/compressors/xz/XZUtils.java | 30 ++---
.../apache/commons/compress/utils/ByteUtils.java | 6 +-
.../utils/FixedLengthBlockOutputStream.java | 2 +-
src/site/xdoc/examples.xml | 2 +-
src/site/xdoc/limitations.xml | 2 +-
src/site/xdoc/mail-lists.xml | 2 +-
src/site/xdoc/zip.xml | 24 ++--
.../apache/commons/compress/AbstractTestCase.java | 2 +-
.../archivers/ar/ArArchiveOutputStreamTest.java | 4 +-
.../compress/archivers/examples/ExpanderTest.java | 4 +-
.../compress/archivers/zip/AsiExtraFieldTest.java | 2 +-
.../archivers/zip/ExtraFieldUtilsTest.java | 2 +-
.../zip/ParallelScatterZipCreatorTest.java | 5 +-
.../compress/archivers/zip/UTF8ZipFilesTest.java | 2 +-
.../compress/changes/ChangeSetTestCase.java | 4 +-
.../lz4/FramedLZ4CompressorInputStreamTest.java | 31 +++++-
.../FramedSnappyCompressorInputStreamTest.java | 2 +-
.../resources/COMPRESS-490/ArithmeticException.lz4 | Bin 0 -> 29 bytes
.../ArrayIndexOutOfBoundsException1.lz4 | 1 +
.../ArrayIndexOutOfBoundsException2.lz4 | Bin 0 -> 405 bytes
79 files changed, 816 insertions(+), 384 deletions(-)
create mode 100644 src/main/java/org/apache/commons/compress/archivers/examples/CloseableConsumer.java
copy src/main/java/org/apache/commons/compress/{utils/CloseShieldFilterInputStream.java => archivers/examples/CloseableConsumerAdapter.java} (59%)
create mode 100644 src/test/resources/COMPRESS-490/ArithmeticException.lz4
create mode 100644 src/test/resources/COMPRESS-490/ArrayIndexOutOfBoundsException1.lz4
create mode 100644 src/test/resources/COMPRESS-490/ArrayIndexOutOfBoundsException2.lz4
[commons-compress] 01/01: COMPRESS-479 allow zip extra fields to be
degraded to unknown on parser errors
Posted by bo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
bodewig pushed a commit to branch COMPRESS-479
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
commit f3f57dc271f0953fd5f36e9ed1c2fe485c81e2d2
Author: Stefan Bodewig <bo...@apache.org>
AuthorDate: Sun May 12 12:14:18 2019 +0200
COMPRESS-479 allow zip extra fields to be degraded to unknown on parser errors
---
.../compress/archivers/zip/ExtraFieldUtils.java | 91 ++++++++++++++++++----
1 file changed, 78 insertions(+), 13 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 304ca38..f6dc7e1 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
@@ -136,6 +136,30 @@ public class ExtraFieldUtils {
public static ZipExtraField[] parse(final byte[] data, final boolean local,
final UnparseableExtraField onUnparseableData)
throws ZipException {
+ return parse(data, local, onUnparseableData, ParseErrorBehavior.THROW);
+ }
+
+ /**
+ * Split the array into ExtraFields and populate them with the
+ * given data.
+ * @param data an array of bytes
+ * @param local whether data originates from the local file data
+ * or the central directory
+ * @param onUnparseableData what to do if the extra field data
+ * cannot be parsed.
+ * @param onParseError what to do if the field's key is recognized
+ * but our implementation class fails to handle it. If the key and
+ * length cannot be parsed at all {@code onUnparseableData} will
+ * determine the behavior.
+ * @return an array of ExtraFields
+ * @throws ZipException on error
+ *
+ * @since 1.19
+ */
+ public static ZipExtraField[] parse(final byte[] data, final boolean local,
+ final UnparseableExtraField onUnparseableData,
+ final ParseErrorBehavior onParseError)
+ throws ZipException {
final List<ZipExtraField> v = new ArrayList<>();
int start = 0;
LOOP:
@@ -173,21 +197,21 @@ public class ExtraFieldUtils {
+ onUnparseableData.getKey());
}
}
- try {
- final ZipExtraField ze = createExtraField(headerId);
+ switch (onParseError) {
+ case MAKE_UNRECOGNIZED:
try {
- if (local) {
- ze.parseFromLocalFileData(data, start + WORD, length);
- } else {
- ze.parseFromCentralDirectoryData(data, start + WORD, length);
- }
- } catch (ArrayIndexOutOfBoundsException aiobe) {
- throw (ZipException) new ZipException("Failed to parse corrupt ZIP extra field of type "
- + Integer.toHexString(headerId.getValue())).initCause(aiobe);
+ v.add(parseField(headerId, local, data, start + WORD, length));
+ } catch (ZipException ex) {
+ final UnrecognizedExtraField u = new UnrecognizedExtraField();
+ u.setHeaderId(headerId);
+ fillField(u, local, data, start + WORD, length);
+ v.add(u);
}
- v.add(ze);
- } catch (final InstantiationException | IllegalAccessException ie) {
- throw (ZipException) new ZipException(ie.getMessage()).initCause(ie);
+ break;
+ case THROW: // FALLTHROUGH
+ default:
+ v.add(parseField(headerId, local, data, start + WORD, length));
+ break;
}
start += length + WORD;
}
@@ -273,6 +297,31 @@ public class ExtraFieldUtils {
return result;
}
+ private static ZipExtraField parseField(final ZipShort headerId, final boolean local, final byte[] data,
+ final int off, final int len) throws ZipException {
+ try {
+ final ZipExtraField ze = createExtraField(headerId);
+ fillField(ze, local, data, off, len);
+ return ze;
+ } catch (final InstantiationException | IllegalAccessException ie) {
+ throw (ZipException) new ZipException(ie.getMessage()).initCause(ie);
+ }
+ }
+
+ private static void fillField(final ZipExtraField ze, final boolean local, final byte[] data, final int off,
+ final int len) throws ZipException {
+ try {
+ if (local) {
+ ze.parseFromLocalFileData(data, off, len);
+ } else {
+ ze.parseFromCentralDirectoryData(data, off, len);
+ }
+ } catch (ArrayIndexOutOfBoundsException aiobe) {
+ throw (ZipException) new ZipException("Failed to parse corrupt ZIP extra field of type "
+ + Integer.toHexString(ze.getHeaderId().getValue())).initCause(aiobe);
+ }
+ }
+
/**
* "enum" for the possible actions to take if the extra field
* cannot be parsed.
@@ -325,4 +374,20 @@ public class ExtraFieldUtils {
*/
public int getKey() { return key; }
}
+
+ /**
+ * What shall {@link #parse} do if parsing the extra field fails.
+ *
+ * @since 1.19
+ */
+ public enum ParseErrorBehavior {
+ /**
+ * Throw an exception if parsing the extra field fails.
+ */
+ THROW,
+ /**
+ * Replace the extra field with an instance of an {@link UnrecognizedExtraField}.
+ */
+ MAKE_UNRECOGNIZED;
+ }
}