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 2020/05/23 16:51:52 UTC
[commons-compress] 02/02: COMPRESS-517 make sure flags and existing
fields agree with each other
This is an automated email from the ASF dual-hosted git repository.
bodewig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
commit f71d3ddd9f9ab2b6c4c072168451e6f72920398f
Author: Stefan Bodewig <bo...@apache.org>
AuthorDate: Sat May 23 18:51:18 2020 +0200
COMPRESS-517 make sure flags and existing fields agree with each other
---
src/changes/changes.xml | 3 +++
.../compress/archivers/zip/X5455_ExtendedTimestamp.java | 6 ++++++
.../compress/archivers/zip/X5455_ExtendedTimestampTest.java | 10 ++++++++++
3 files changed, 19 insertions(+)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index db5a000..dcad6f0 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -73,6 +73,9 @@ The <action> type attribute can be add,update,fix,remove.
throw the expected IOException rather than obscure
RuntimeExceptions.
</action>
+ <action issue="COMPRESS-517" type="fix" date="2020-05-23">
+ Improved parsing of X5455_ExtendedTimestamp ZIP extra field.
+ </action>
</release>
<release version="1.20" date="2020-02-08"
description="Release 1.20">
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestamp.java b/src/main/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestamp.java
index bfc0b0d..02f5bc9 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestamp.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestamp.java
@@ -227,14 +227,20 @@ public class X5455_ExtendedTimestamp implements ZipExtraField, Cloneable, Serial
if (bit0_modifyTimePresent && offset + 4 <= len) {
modifyTime = new ZipLong(data, offset);
offset += 4;
+ } else {
+ bit0_modifyTimePresent = false;
}
if (bit1_accessTimePresent && offset + 4 <= len) {
accessTime = new ZipLong(data, offset);
offset += 4;
+ } else {
+ bit1_accessTimePresent = false;
}
if (bit2_createTimePresent && offset + 4 <= len) {
createTime = new ZipLong(data, offset);
offset += 4; // NOSONAR - assignment as documentation
+ } else {
+ bit2_createTimePresent = false;
}
}
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestampTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestampTest.java
index e3bd60e..51a807e 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestampTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestampTest.java
@@ -39,6 +39,7 @@ import static org.apache.commons.compress.AbstractTestCase.rmdir;
import static org.apache.commons.compress.archivers.zip.X5455_ExtendedTimestamp.ACCESS_TIME_BIT;
import static org.apache.commons.compress.archivers.zip.X5455_ExtendedTimestamp.CREATE_TIME_BIT;
import static org.apache.commons.compress.archivers.zip.X5455_ExtendedTimestamp.MODIFY_TIME_BIT;
+import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -472,6 +473,15 @@ public class X5455_ExtendedTimestampTest {
assertEquals(0, xf.getFlags());
}
+ @Test
+ public void resetsFlagsWhenLocalFileArrayIsTooShort() throws Exception {
+ final byte[] local = new byte[] {
+ 7
+ }; // claims all three time values would be present, but they are not
+ xf.parseFromLocalFileData(local, 0, 1);
+ assertArrayEquals(new byte[1], xf.getLocalFileDataData());
+ }
+
private void parseReparse(
final ZipLong time,
final byte[] expectedLocal,