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 2017/07/04 08:56:44 UTC
[1/6] commons-compress git commit: COMPRESS-416 Use signed integers
for extended timestamps, per spec
Repository: commons-compress
Updated Branches:
refs/heads/master 992911d0f -> 9052f4df8
COMPRESS-416 Use signed integers for extended timestamps, per spec
Signed-off-by: Simon Spero <se...@gmail.com>
Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/cd1d329d
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/cd1d329d
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/cd1d329d
Branch: refs/heads/master
Commit: cd1d329dba95dae161317c123269c24282001a66
Parents: d0595b7
Author: Simon Spero <se...@gmail.com>
Authored: Mon Jul 3 19:10:10 2017 -0400
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Tue Jul 4 08:51:32 2017 +0200
----------------------------------------------------------------------
.../archivers/zip/X5455_ExtendedTimestamp.java | 24 ++++--
.../zip/X5455_ExtendedTimestampTest.java | 86 +++++++-------------
2 files changed, 43 insertions(+), 67 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/cd1d329d/src/main/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestamp.java
----------------------------------------------------------------------
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 90bd750..f050874 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
@@ -25,14 +25,14 @@ import java.util.zip.ZipException;
/**
* <p>An extra field that stores additional file and directory timestamp data
* for zip entries. Each zip entry can include up to three timestamps
- * (modify, access, create*). The timestamps are stored as 32 bit unsigned
+ * (modify, access, create*). The timestamps are stored as 32 bit signed
* integers representing seconds since UNIX epoch (Jan 1st, 1970, UTC).
* This field improves on zip's default timestamp granularity, since it
* allows one to store additional timestamps, and, in addition, the timestamps
* are stored using per-second granularity (zip's default behaviour can only store
* timestamps to the nearest <em>even</em> second).
* </p><p>
- * Unfortunately, 32 (unsigned) bits can only store dates up to the year 2106,
+ * Unfortunately, 32 (signed) bits can only store dates up to the year 2037,
* and so this extra field will eventually be obsolete. Enjoy it while it lasts!
* </p>
* <ul>
@@ -370,7 +370,7 @@ public class X5455_ExtendedTimestamp implements ZipExtraField, Cloneable, Serial
* @return modify time as java.util.Date or null.
*/
public Date getModifyJavaTime() {
- return modifyTime != null ? new Date(modifyTime.getValue() * 1000) : null;
+ return zipLongToDate(modifyTime);
}
/**
@@ -382,7 +382,11 @@ public class X5455_ExtendedTimestamp implements ZipExtraField, Cloneable, Serial
* @return access time as java.util.Date or null.
*/
public Date getAccessJavaTime() {
- return accessTime != null ? new Date(accessTime.getValue() * 1000) : null;
+ return zipLongToDate(accessTime);
+ }
+
+ private static Date zipLongToDate(ZipLong unixTime) {
+ return unixTime != null ? new Date(unixTime.getIntValue() * 1000L) : null;
}
/**
@@ -400,7 +404,7 @@ public class X5455_ExtendedTimestamp implements ZipExtraField, Cloneable, Serial
* @return create time as java.util.Date or null.
*/
public Date getCreateJavaTime() {
- return createTime != null ? new Date(createTime.getValue() * 1000) : null;
+ return zipLongToDate(createTime);
}
/**
@@ -518,10 +522,12 @@ public class X5455_ExtendedTimestamp implements ZipExtraField, Cloneable, Serial
private static ZipLong dateToZipLong(final Date d) {
if (d == null) { return null; }
- final long TWO_TO_32 = 0x100000000L;
- final long l = d.getTime() / 1000;
- if (l >= TWO_TO_32) {
- throw new IllegalArgumentException("Cannot set an X5455 timestamp larger than 2^32: " + l);
+ return unixTimeToZipLong(d.getTime() / 1000);
+ }
+
+ private static ZipLong unixTimeToZipLong(long l) {
+ if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
+ throw new IllegalArgumentException("X5455 timestamps must fit in a signed 32 bit integer: " + l);
}
return new ZipLong(l);
}
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/cd1d329d/src/test/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestampTest.java
----------------------------------------------------------------------
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 06c77d3..a0d9666 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
@@ -50,7 +50,7 @@ public class X5455_ExtendedTimestampTest {
private final static ZipShort X5455 = new ZipShort(0x5455);
private final static ZipLong ZERO_TIME = new ZipLong(0);
- private final static ZipLong MAX_TIME_SECONDS = new ZipLong(0xFFFFFFFFL);
+ private final static ZipLong MAX_TIME_SECONDS = new ZipLong(Integer.MAX_VALUE);
private final static SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd/HH:mm:ss Z");
static {
@@ -142,51 +142,19 @@ public class X5455_ExtendedTimestampTest {
}
if (year >= 0) {
switch (year) {
- case 2107:
- if (!zipTimeUsesExtendedTimestamp) {
- // Zip time is okay up to 2107.
- assertEquals(year + "-01-01/00:00:02 +0000", zipTime);
- }
- // But the X5455 data has overflowed:
- assertEquals("1970-11-24/17:31:45 +0000", modTime);
- assertEquals("1970-11-24/17:31:47 +0000", accTime);
- break;
- case 2108:
- if (!zipTimeUsesExtendedTimestamp) {
- // Zip time is still okay at Jan 1st midnight (UTC) in 2108
- // because we created the zip file in pacific time zone, so it's
- // actually still 2107 in the zip file!
- assertEquals(year + "-01-01/00:00:02 +0000", zipTime);
- }
- // The X5455 data is still overflowed, of course:
- assertEquals("1971-11-24/17:31:45 +0000", modTime);
- assertEquals("1971-11-24/17:31:47 +0000", accTime);
- break;
- case 2109:
- // All three timestamps have overflowed by 2109.
- if (!zipTimeUsesExtendedTimestamp) {
- assertEquals("1981-01-01/00:00:02 +0000", zipTime);
- }
- assertEquals("1972-11-24/17:31:45 +0000", modTime);
- assertEquals("1972-11-24/17:31:47 +0000", accTime);
-
- // Hmmm.... looks like one could examine both DOS time
- // and the Unix time together to hack a nice workaround to
- // get timestamps past 2106 in a reverse-compatible way.
-
- break;
default:
if (!zipTimeUsesExtendedTimestamp) {
- // X5455 time is good from epoch (1970) to 2106.
+ // X5455 time is good from epoch (1970) to 2037.
// Zip time is good from 1980 to 2107.
if (year < 1980) {
assertEquals("1980-01-01/08:00:00 +0000", zipTime);
} else {
assertEquals(year + "-01-01/00:00:02 +0000", zipTime);
}
- }
+ }if(year <2038) {
assertEquals(year + "-01-01/00:00:01 +0000", modTime);
assertEquals(year + "-01-01/00:00:03 +0000", accTime);
+ }
break;
}
}
@@ -235,9 +203,10 @@ public class X5455_ExtendedTimestampTest {
cal.set(Calendar.DATE, 1);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
+ cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
- final Date timeMillis = cal.getTime();
- final ZipLong time = new ZipLong(timeMillis.getTime() / 1000);
+ final long timeMillis = cal.getTimeInMillis();
+ final ZipLong time = new ZipLong(timeMillis / 1000);
// set too big
try {
@@ -251,14 +220,15 @@ public class X5455_ExtendedTimestampTest {
// get/set modify time
xf.setModifyTime(time);
assertEquals(time, xf.getModifyTime());
- assertEquals(timeMillis, xf.getModifyJavaTime());
- xf.setModifyJavaTime(timeMillis);
+ Date xfModifyJavaTime = xf.getModifyJavaTime();
+ assertEquals(timeMillis, xfModifyJavaTime.getTime());
+ xf.setModifyJavaTime(new Date(timeMillis));
assertEquals(time, xf.getModifyTime());
- assertEquals(timeMillis, xf.getModifyJavaTime());
+ assertEquals(timeMillis, xf.getModifyJavaTime().getTime());
// Make sure milliseconds get zeroed out:
- xf.setModifyJavaTime(new Date(timeMillis.getTime() + 123));
+ xf.setModifyJavaTime(new Date(timeMillis + 123));
assertEquals(time, xf.getModifyTime());
- assertEquals(timeMillis, xf.getModifyJavaTime());
+ assertEquals(timeMillis, xf.getModifyJavaTime().getTime());
// Null
xf.setModifyTime(null);
assertNull(xf.getModifyJavaTime());
@@ -268,14 +238,14 @@ public class X5455_ExtendedTimestampTest {
// get/set access time
xf.setAccessTime(time);
assertEquals(time, xf.getAccessTime());
- assertEquals(timeMillis, xf.getAccessJavaTime());
- xf.setAccessJavaTime(timeMillis);
+ assertEquals(timeMillis, xf.getAccessJavaTime().getTime());
+ xf.setAccessJavaTime(new Date(timeMillis));
assertEquals(time, xf.getAccessTime());
- assertEquals(timeMillis, xf.getAccessJavaTime());
+ assertEquals(timeMillis, xf.getAccessJavaTime().getTime());
// Make sure milliseconds get zeroed out:
- xf.setAccessJavaTime(new Date(timeMillis.getTime() + 123));
+ xf.setAccessJavaTime(new Date(timeMillis + 123));
assertEquals(time, xf.getAccessTime());
- assertEquals(timeMillis, xf.getAccessJavaTime());
+ assertEquals(timeMillis, xf.getAccessJavaTime().getTime());
// Null
xf.setAccessTime(null);
assertNull(xf.getAccessJavaTime());
@@ -285,14 +255,14 @@ public class X5455_ExtendedTimestampTest {
// get/set create time
xf.setCreateTime(time);
assertEquals(time, xf.getCreateTime());
- assertEquals(timeMillis, xf.getCreateJavaTime());
- xf.setCreateJavaTime(timeMillis);
+ assertEquals(timeMillis, xf.getCreateJavaTime().getTime());
+ xf.setCreateJavaTime(new Date(timeMillis));
assertEquals(time, xf.getCreateTime());
- assertEquals(timeMillis, xf.getCreateJavaTime());
+ assertEquals(timeMillis, xf.getCreateJavaTime().getTime());
// Make sure milliseconds get zeroed out:
- xf.setCreateJavaTime(new Date(timeMillis.getTime() + 123));
+ xf.setCreateJavaTime(new Date(timeMillis + 123));
assertEquals(time, xf.getCreateTime());
- assertEquals(timeMillis, xf.getCreateJavaTime());
+ assertEquals(timeMillis, xf.getCreateJavaTime().getTime());
// Null
xf.setCreateTime(null);
assertNull(xf.getCreateJavaTime());
@@ -388,15 +358,15 @@ public class X5455_ExtendedTimestampTest {
final byte[] CR_CENTRAL = {4}; // central data only dontains the CR flag and no actual data
final byte[] MOD_ZERO = {1, 0, 0, 0, 0};
- final byte[] MOD_MAX = {1, -1, -1, -1, -1};
+ final byte[] MOD_MAX = {1, -1, -1, -1, 0x7f};
final byte[] AC_ZERO = {2, 0, 0, 0, 0};
- final byte[] AC_MAX = {2, -1, -1, -1, -1};
+ final byte[] AC_MAX = {2, -1, -1, -1, 0x7f};
final byte[] CR_ZERO = {4, 0, 0, 0, 0};
- final byte[] CR_MAX = {4, -1, -1, -1, -1};
+ final byte[] CR_MAX = {4, -1, -1, -1, 0x7f};
final byte[] MOD_AC_ZERO = {3, 0, 0, 0, 0, 0, 0, 0, 0};
- final byte[] MOD_AC_MAX = {3, -1, -1, -1, -1, -1, -1, -1, -1};
+ final byte[] MOD_AC_MAX = {3, -1, -1, -1, 0x7f, -1, -1, -1, 0x7f};
final byte[] MOD_AC_CR_ZERO = {7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- final byte[] MOD_AC_CR_MAX = {7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
+ final byte[] MOD_AC_CR_MAX = {7, -1, -1, -1, 0x7f, -1, -1, -1, 0x7f, -1, -1, -1, 0x7f};
parseReparse(null, NULL_FLAGS, NULL_FLAGS);
parseReparse(ZERO_TIME, MOD_ZERO, MOD_ZERO);
[2/6] commons-compress git commit: COMPRESS-416 Add signed 32bit int
constructor and accessor to ZipLong
Posted by bo...@apache.org.
COMPRESS-416 Add signed 32bit int constructor and accessor to ZipLong
Signed-off-by: Simon Spero <se...@gmail.com>
Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/d0595b71
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/d0595b71
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/d0595b71
Branch: refs/heads/master
Commit: d0595b7121f57f1f49fe7fdc384479dd73ad64f5
Parents: 992911d
Author: Simon Spero <se...@gmail.com>
Authored: Mon Jul 3 18:24:55 2017 -0400
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Tue Jul 4 08:51:32 2017 +0200
----------------------------------------------------------------------
.../commons/compress/archivers/zip/ZipLong.java | 18 ++++++++++++++++--
.../compress/archivers/zip/ZipLongTest.java | 13 ++++++++++---
2 files changed, 26 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/d0595b71/src/main/java/org/apache/commons/compress/archivers/zip/ZipLong.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipLong.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipLong.java
index 2976183..07da7d5 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipLong.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipLong.java
@@ -17,10 +17,10 @@
*/
package org.apache.commons.compress.archivers.zip;
-import java.io.Serializable;
-
import org.apache.commons.compress.utils.ByteUtils;
+import java.io.Serializable;
+
import static org.apache.commons.compress.archivers.zip.ZipConstants.WORD;
/**
@@ -82,6 +82,14 @@ public final class ZipLong implements Cloneable, Serializable {
}
/**
+ * create instance from a java int.
+ * @param value
+ */
+ public ZipLong(int value) {
+ this.value = value;
+ }
+
+ /**
* Create instance from bytes.
* @param bytes the bytes to store as a ZipLong
*/
@@ -115,6 +123,12 @@ public final class ZipLong implements Cloneable, Serializable {
}
/**
+ * Get value as a (signed) java int
+ * @return
+ */
+ public int getIntValue() { return (int)value;}
+
+ /**
* Get value as four bytes in big endian byte order.
* @param value the value to convert
* @return value as four bytes in big endian byte order
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/d0595b71/src/test/java/org/apache/commons/compress/archivers/zip/ZipLongTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipLongTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipLongTest.java
index f72d886..75709fd 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipLongTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipLongTest.java
@@ -18,10 +18,10 @@
package org.apache.commons.compress.archivers.zip;
-import static org.junit.Assert.*;
-
import org.junit.Test;
+import static org.junit.Assert.*;
+
/**
* JUnit testcases for org.apache.commons.compress.archivers.zip.ZipLong.
*
@@ -90,8 +90,15 @@ public class ZipLongTest {
*/
@Test
public void testSign() {
- final ZipLong zl = new ZipLong(new byte[] {(byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF});
+ ZipLong zl = new ZipLong(new byte[] {(byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF});
assertEquals(0x00000000FFFFFFFFl, zl.getValue());
+ assertEquals(-1,zl.getIntValue());
+
+ zl = new ZipLong(0xFFFF_FFFFL);
+ assertEquals(0x00000000FFFFFFFFl, zl.getValue());
+ zl = new ZipLong(0xFFFF_FFFF);
+ assertEquals(0xFFFF_FFFF_FFFF_FFFFL, zl.getValue());
+
}
@Test
[6/6] commons-compress git commit: COMPRESS-416 document X5455 fix
Posted by bo...@apache.org.
COMPRESS-416 document X5455 fix
closes #48
Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/9052f4df
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/9052f4df
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/9052f4df
Branch: refs/heads/master
Commit: 9052f4df8d3fe61632dbb4f48a257954d2eade81
Parents: 2ed2771
Author: Stefan Bodewig <bo...@apache.org>
Authored: Tue Jul 4 10:56:01 2017 +0200
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Tue Jul 4 10:56:01 2017 +0200
----------------------------------------------------------------------
src/changes/changes.xml | 6 ++++++
1 file changed, 6 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/9052f4df/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index b1db317..79405a9 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -102,6 +102,12 @@ wanted to create such files.">
Fixed classnames of CpioArchiveEntry and
CpioArchiveInputStream in variuous javadocs.
</action>
+ <action issue="COMPRESS-416" type="fix" date="2017-07-04"
+ due-to="Simon Spero ">
+ The code of the extended timestamp zip extra field incorrectly
+ assumed the time was stored as unsigned 32bit int and thus
+ created incorrect results for years after 2037.
+ </action>
</release>
<release version="1.14" date="2017-05-14"
description="Release 1.14">
[3/6] commons-compress git commit: COMPRESS-416 cosmetics
Posted by bo...@apache.org.
COMPRESS-416 cosmetics
Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/8251cd68
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/8251cd68
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/8251cd68
Branch: refs/heads/master
Commit: 8251cd68f4db4bd56d88646e10d34ef4a1fdf90f
Parents: cd1d329
Author: Stefan Bodewig <bo...@apache.org>
Authored: Tue Jul 4 08:54:24 2017 +0200
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Tue Jul 4 08:56:00 2017 +0200
----------------------------------------------------------------------
.../archivers/zip/X5455_ExtendedTimestamp.java | 22 ++++++++++----------
.../zip/X5455_ExtendedTimestampTest.java | 9 ++++----
2 files changed, 16 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/8251cd68/src/main/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestamp.java
----------------------------------------------------------------------
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 f050874..28590c2 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
@@ -385,10 +385,6 @@ public class X5455_ExtendedTimestamp implements ZipExtraField, Cloneable, Serial
return zipLongToDate(accessTime);
}
- private static Date zipLongToDate(ZipLong unixTime) {
- return unixTime != null ? new Date(unixTime.getIntValue() * 1000L) : null;
- }
-
/**
* <p>
* Returns the create time as a a java.util.Date
@@ -525,13 +521,6 @@ public class X5455_ExtendedTimestamp implements ZipExtraField, Cloneable, Serial
return unixTimeToZipLong(d.getTime() / 1000);
}
- private static ZipLong unixTimeToZipLong(long l) {
- if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
- throw new IllegalArgumentException("X5455 timestamps must fit in a signed 32 bit integer: " + l);
- }
- return new ZipLong(l);
- }
-
/**
* Returns a String representation of this class useful for
* debugging purposes.
@@ -596,4 +585,15 @@ public class X5455_ExtendedTimestamp implements ZipExtraField, Cloneable, Serial
return hc;
}
+ private static Date zipLongToDate(ZipLong unixTime) {
+ return unixTime != null ? new Date(unixTime.getIntValue() * 1000L) : null;
+ }
+
+ private static ZipLong unixTimeToZipLong(long l) {
+ if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
+ throw new IllegalArgumentException("X5455 timestamps must fit in a signed 32 bit integer: " + l);
+ }
+ return new ZipLong(l);
+ }
+
}
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/8251cd68/src/test/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestampTest.java
----------------------------------------------------------------------
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 a0d9666..40db766 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
@@ -151,10 +151,11 @@ public class X5455_ExtendedTimestampTest {
} else {
assertEquals(year + "-01-01/00:00:02 +0000", zipTime);
}
- }if(year <2038) {
- assertEquals(year + "-01-01/00:00:01 +0000", modTime);
- assertEquals(year + "-01-01/00:00:03 +0000", accTime);
- }
+ }
+ if (year < 2038) {
+ assertEquals(year + "-01-01/00:00:01 +0000", modTime);
+ assertEquals(year + "-01-01/00:00:03 +0000", accTime);
+ }
break;
}
}
[5/6] commons-compress git commit: remove test now we know Java9 is
correct and we've adapted
Posted by bo...@apache.org.
remove test now we know Java9 is correct and we've adapted
Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/2ed2771c
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/2ed2771c
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/2ed2771c
Branch: refs/heads/master
Commit: 2ed2771ca993f24ec6a9511f870d1612a58cfcf7
Parents: 8526b85
Author: Stefan Bodewig <bo...@apache.org>
Authored: Tue Jul 4 10:52:44 2017 +0200
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Tue Jul 4 10:52:44 2017 +0200
----------------------------------------------------------------------
.../archivers/zip/Java9ZipEntryTimeTest.java | 48 --------------------
1 file changed, 48 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/2ed2771c/src/test/java/org/apache/commons/compress/archivers/zip/Java9ZipEntryTimeTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/Java9ZipEntryTimeTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/Java9ZipEntryTimeTest.java
deleted file mode 100644
index d5a641b..0000000
--- a/src/test/java/org/apache/commons/compress/archivers/zip/Java9ZipEntryTimeTest.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.commons.compress.archivers.zip;
-
-import java.io.File;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.TimeZone;
-import java.util.zip.ZipEntry;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-public class Java9ZipEntryTimeTest {
-
- /**
- * Fails on Java 9.
- *
- * @throws Exception
- */
- @Test
- public void testJUZTimes() throws Exception {
- final File archive = new File("src/test/resources/COMPRESS-210_unix_time_zip_test.zip");
- try (java.util.zip.ZipFile zf = new java.util.zip.ZipFile(archive)) {
- final ZipEntry entry = zf.getEntry("COMPRESS-210_unix_time_zip_test/2105");
- final Calendar girl = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
- girl.setTime(new Date(entry.getTime()));
- final int year = girl.get(Calendar.YEAR);
- Assert.assertEquals(2105, year);
- }
- }
-}
[4/6] commons-compress git commit: adjust to Java8 vs Java9
differences in timezones != pacific
Posted by bo...@apache.org.
adjust to Java8 vs Java9 differences in timezones != pacific
Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/8526b85e
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/8526b85e
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/8526b85e
Branch: refs/heads/master
Commit: 8526b85e269b87187008b502692406a5ab1bb907
Parents: 8251cd6
Author: Stefan Bodewig <bo...@apache.org>
Authored: Tue Jul 4 10:49:47 2017 +0200
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Tue Jul 4 10:49:47 2017 +0200
----------------------------------------------------------------------
.../zip/X5455_ExtendedTimestampTest.java | 79 +++++++++++++-------
1 file changed, 53 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/8526b85e/src/test/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestampTest.java
----------------------------------------------------------------------
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 40db766..97df90c 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
@@ -105,6 +105,12 @@ public class X5455_ExtendedTimestampTest {
uses the extended time stamp field itself and should be the
same as "mod time".
http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/rev/90df6756406f
+
+ Starting with Java9 the parser for extended time stamps has
+ been fixed to use signed integers which was detected during
+ the triage of COMPRESS-416. Signed integers is the correct
+ format and Compress 1.15 has started to use signed integers as
+ well.
*/
final File archive = getFile("COMPRESS-210_unix_time_zip_test.zip");
@@ -119,11 +125,37 @@ public class X5455_ExtendedTimestampTest {
while (en.hasMoreElements()) {
final ZipArchiveEntry zae = en.nextElement();
+ if (zae.isDirectory()) {
+ continue;
+ }
final String name = zae.getName();
+ final int x = name.lastIndexOf('/');
+ final String yearString = name.substring(x + 1);
+ int year;
+ try {
+ year = Integer.parseInt(yearString);
+ } catch (final NumberFormatException nfe) {
+ // setTime.sh, skip
+ continue;
+ }
+
final X5455_ExtendedTimestamp xf = (X5455_ExtendedTimestamp) zae.getExtraField(X5455);
final Date rawZ = zae.getLastModifiedDate();
final Date m = xf.getModifyJavaTime();
- final boolean zipTimeUsesExtendedTimestamp = rawZ.equals(m);
+
+ /*
+ We must distinguish three cases:
+ - Java has read the extended time field itself and agrees with us (Java9 or Java8 and years prior to
+ 2028)
+ - Java has read the extended time field but found a year >= 2038 (Java8)
+ - Java hasn't read the extended time field at all (Java7- or early Java8)
+ */
+
+ final boolean zipTimeUsesExtendedTimestampCorrectly = rawZ.equals(m);
+ final boolean zipTimeUsesExtendedTimestampButUnsigned = year > 2037 && rawZ.getSeconds() == 1;
+ final boolean zipTimeUsesExtendedTimestamp = zipTimeUsesExtendedTimestampCorrectly
+ || zipTimeUsesExtendedTimestampButUnsigned;
+
final Date z = zipTimeUsesExtendedTimestamp ? rawZ : adjustFromGMTToExpectedOffset(rawZ);
final Date a = xf.getAccessJavaTime();
@@ -131,34 +163,29 @@ public class X5455_ExtendedTimestampTest {
final String modTime = DATE_FORMAT.format(m);
final String accTime = DATE_FORMAT.format(a);
- if (!zae.isDirectory()) {
- final int x = name.lastIndexOf('/');
- final String yearString = name.substring(x + 1);
- int year;
- try {
- year = Integer.parseInt(yearString);
- } catch (final NumberFormatException nfe) {
- year = -1;
+ switch (year) {
+ case 2109:
+ // All three timestamps have overflowed by 2109.
+ if (!zipTimeUsesExtendedTimestamp) {
+ assertEquals("1981-01-01/00:00:02 +0000", zipTime);
}
- if (year >= 0) {
- switch (year) {
- default:
- if (!zipTimeUsesExtendedTimestamp) {
- // X5455 time is good from epoch (1970) to 2037.
- // Zip time is good from 1980 to 2107.
- if (year < 1980) {
- assertEquals("1980-01-01/08:00:00 +0000", zipTime);
- } else {
- assertEquals(year + "-01-01/00:00:02 +0000", zipTime);
- }
- }
- if (year < 2038) {
- assertEquals(year + "-01-01/00:00:01 +0000", modTime);
- assertEquals(year + "-01-01/00:00:03 +0000", accTime);
- }
- break;
+ break;
+ default:
+ if (!zipTimeUsesExtendedTimestamp) {
+ // X5455 time is good from epoch (1970) to 2037.
+ // Zip time is good from 1980 to 2107.
+ if (year < 1980) {
+ assertEquals("1980-01-01/08:00:00 +0000", zipTime);
+ } else {
+ assertEquals(year + "-01-01/00:00:02 +0000", zipTime);
}
}
+
+ if (year < 2038) {
+ assertEquals(year + "-01-01/00:00:01 +0000", modTime);
+ assertEquals(year + "-01-01/00:00:03 +0000", accTime);
+ }
+ break;
}
}
} finally {