You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/09/11 23:16:02 UTC
(commons-compress) branch master updated: ZipArchiveOutputStream.addRawArchiveEntry() should check is2PhaseSource (#571)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
The following commit(s) were added to refs/heads/master by this push:
new 6bed6b7f5 ZipArchiveOutputStream.addRawArchiveEntry() should check is2PhaseSource (#571)
6bed6b7f5 is described below
commit 6bed6b7f536aac29baca663ca83d20557b49b0b8
Author: LoveSy <sh...@zju.edu.cn>
AuthorDate: Thu Sep 12 07:15:57 2024 +0800
ZipArchiveOutputStream.addRawArchiveEntry() should check is2PhaseSource (#571)
* Don't check requested features for is2PhaseSource
This allow user to add manually compressed raw data to the zip file
under unsupported compression method (e.g., XZ) or encrypt method
* Add test for addRawArchiveEntry with unsupported compression method
---
.../compress/archivers/zip/ZipArchiveOutputStream.java | 8 +++++---
.../java/org/apache/commons/compress/archivers/ZipTest.java | 13 +++++++++++++
2 files changed, 18 insertions(+), 3 deletions(-)
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 0ee3ab731..3bf24aca8 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
@@ -505,7 +505,7 @@ public class ZipArchiveOutputStream extends ArchiveOutputStream<ZipArchiveEntry>
final boolean is2PhaseSource = ae.getCrc() != ZipArchiveEntry.CRC_UNKNOWN && ae.getSize() != ArchiveEntry.SIZE_UNKNOWN
&& ae.getCompressedSize() != ArchiveEntry.SIZE_UNKNOWN;
putArchiveEntry(ae, is2PhaseSource);
- copyFromZipInputStream(rawStream);
+ copyFromZipInputStream(rawStream, is2PhaseSource);
closeCopiedEntry(is2PhaseSource);
}
@@ -622,11 +622,13 @@ public class ZipArchiveOutputStream extends ArchiveOutputStream<ZipArchiveEntry>
entry = null;
}
- private void copyFromZipInputStream(final InputStream src) throws IOException {
+ private void copyFromZipInputStream(final InputStream src, boolean phased) throws IOException {
if (entry == null) {
throw new IllegalStateException("No current entry");
}
- ZipUtil.checkRequestedFeatures(entry.entry);
+ if (!phased) {
+ ZipUtil.checkRequestedFeatures(entry.entry);
+ }
entry.hasWritten = true;
int length;
while ((length = src.read(copyBuffer)) >= 0) {
diff --git a/src/test/java/org/apache/commons/compress/archivers/ZipTest.java b/src/test/java/org/apache/commons/compress/archivers/ZipTest.java
index 42c9fb11d..f8c66a289 100644
--- a/src/test/java/org/apache/commons/compress/archivers/ZipTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/ZipTest.java
@@ -738,6 +738,19 @@ public final class ZipTest extends AbstractTest {
}
}
+ @Test
+ public void testUnsupportedCompressionMethodInAddRaw() throws IOException {
+ final File file1 = createTempFile("unsupportedCompressionMethod.", ".zip");
+ try (ZipArchiveOutputStream zos = new ZipArchiveOutputStream(file1)) {
+ final ZipArchiveEntry archiveEntry = new ZipArchiveEntry("fred");
+ archiveEntry.setMethod(Integer.MAX_VALUE);
+ archiveEntry.setSize(3);
+ archiveEntry.setCompressedSize(3);
+ archiveEntry.setCrc(0);
+ zos.addRawArchiveEntry(archiveEntry, new ByteArrayInputStream("fud".getBytes()));
+ }
+ }
+
/**
* Archives 2 files and unarchives it again. If the file length of result and source is the same, it looks like the operations have worked
*