8210899: (zipfs) ZipFileSystem.EntryOutputStreamCRC32 mistakenly set the crc32 value into size field

Reviewed-by: bpb
This commit is contained in:
Xueming Shen 2018-09-18 19:44:27 -07:00
parent 4aa926a9eb
commit f0108ea40c
2 changed files with 30 additions and 5 deletions

View File

@ -612,6 +612,10 @@ class ZipFileSystem extends FileSystem {
}
}
private int getCompressMethod(FileAttribute<?>... attrs) {
return defaultMethod;
}
// Returns a Writable/ReadByteChannel for now. Might consdier to use
// newFileChannel() instead, which dump the entry data into a regular
// file on the default file system and create a FileChannel on top of
@ -653,7 +657,7 @@ class ZipFileSystem extends FileSystem {
throw new NoSuchFileException(getString(path));
checkParents(path);
return new EntryOutputChannel(
new Entry(path, Entry.NEW, false, defaultMethod));
new Entry(path, Entry.NEW, false, getCompressMethod(attrs)));
} finally {
endRead();
@ -721,7 +725,7 @@ class ZipFileSystem extends FileSystem {
final Entry u = isFCH ? e : new Entry(path, tmpfile, Entry.FILECH);
if (forWrite) {
u.flag = FLAG_DATADESCR;
u.method = METHOD_DEFLATED;
u.method = getCompressMethod(attrs);
}
// is there a better way to hook into the FileChannel's close method?
return new FileChannel() {
@ -1407,7 +1411,7 @@ class ZipFileSystem extends FileSystem {
return;
isClosed = true;
e.size = e.csize = written;
e.size = crc.getValue();
e.crc = crc.getValue();
}
}

View File

@ -73,7 +73,7 @@ import static java.nio.file.StandardCopyOption.*;
* @test
* @bug 6990846 7009092 7009085 7015391 7014948 7005986 7017840 7007596
* 7157656 8002390 7012868 7012856 8015728 8038500 8040059 8069211
* 8131067 8034802
* 8131067 8034802 8210899
* @summary Test Zip filesystem provider
* @modules jdk.zipfs
* @run main ZipFSTester
@ -95,7 +95,6 @@ public class ZipFSTester {
test1(fs);
test2(fs); // more tests
}
testStreamChannel();
testTime(jarFile);
test8069211();
@ -434,6 +433,28 @@ public class ZipFSTester {
// check the content of read from zipfs is equal to the "bytes"
private static void checkRead(Path path, byte[] expected) throws IOException {
// fileAttribute
CRC32 crc32 = new CRC32();
crc32.update(expected);
if (((Long)Files.getAttribute(path, "zip:crc")).intValue() !=
(int)crc32.getValue()) {
System.out.printf(" getAttribute.crc <%s> failed %x vs %x ...%n",
path.toString(),
((Long)Files.getAttribute(path, "zip:crc")).intValue(),
(int)crc32.getValue());
throw new RuntimeException("CHECK FAILED!");
}
if (((Long)Files.getAttribute(path, "zip:size")).intValue() != expected.length) {
System.out.printf(" getAttribute.size <%s> failed %x vs %x ...%n",
path.toString(),
((Long)Files.getAttribute(path, "zip:size")).intValue(),
expected.length);
throw new RuntimeException("CHECK FAILED!");
}
//streams
try (InputStream is = Files.newInputStream(path)) {
if (!Arrays.equals(is.readAllBytes(), expected)) {