8223597: jdk/nio/zipfs/ZipFSTester.java RuntimeException: CHECK_FAILED! (getAttribute.crc <entries20> failed 6af4413c vs 0 ...)
authorclanger
Tue, 14 May 2019 09:25:58 +0100
changeset 54835 43764a3a986d
parent 54834 39ba09047e19
child 54836 e2ed0691ae79
8223597: jdk/nio/zipfs/ZipFSTester.java RuntimeException: CHECK_FAILED! (getAttribute.crc <entries20> failed 6af4413c vs 0 ...) Reviewed-by: redestad, lancea
src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java
test/jdk/jdk/nio/zipfs/ZipFSTester.java
--- a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java	Tue May 14 09:55:02 2019 +0200
+++ b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java	Tue May 14 09:25:58 2019 +0100
@@ -1211,7 +1211,7 @@
             return 0;
 
         long written = 0;
-        if (e.crc != 0 && e.csize > 0) {
+        if (e.csize > 0 && (e.crc != 0 || e.size == 0)) {
             // pre-compressed entry, write directly to output stream
             writeTo(e, os);
         } else {
--- a/test/jdk/jdk/nio/zipfs/ZipFSTester.java	Tue May 14 09:55:02 2019 +0200
+++ b/test/jdk/jdk/nio/zipfs/ZipFSTester.java	Tue May 14 09:25:58 2019 +0100
@@ -228,7 +228,7 @@
                 Files.newInputStream(parent);
                 throw new RuntimeException("Failed");
             } catch (FileSystemException e) {
-                e.printStackTrace();    // expected fse
+                // expected fse
             }
 
             // rmdirs
@@ -420,7 +420,15 @@
 
     static Object[][] getEntries() {
         Object[][] entries = new Object[10 + rdm.nextInt(20)][3];
-        for (int i = 0; i < entries.length; i++) {
+        // first entries shall test the corner case of 0 bytes of data
+        entries[0][0] = "entries" + 0;
+        entries[0][1] = METHOD_STORED;
+        entries[0][2] = new byte[0];
+        entries[1][0] = "entries" + 1;
+        entries[1][1] = METHOD_DEFLATED;
+        entries[1][2] = new byte[0];
+        // the rest is random data
+        for (int i = 2; i < entries.length; i++) {
             entries[i][0] = "entries" + i;
             entries[i][1] = rdm.nextInt(10) % 2 == 0 ?
                 METHOD_STORED : METHOD_DEFLATED;