8240333: jmod incorrectly updates .jar and .jmod files during hashing
Reviewed-by: martin, alanb, lancea
This commit is contained in:
parent
128f083359
commit
ff843fabec
src/jdk.jlink/share/classes/jdk/tools/jmod
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -92,7 +92,20 @@ class JmodOutputStream extends OutputStream implements AutoCloseable {
|
||||
* Writes the given entry to the given input stream.
|
||||
*/
|
||||
public void writeEntry(InputStream in, Entry e) throws IOException {
|
||||
zos.putNextEntry(e.zipEntry());
|
||||
ZipEntry e1 = e.zipEntry();
|
||||
// Only preserve attributes which won't change by
|
||||
// inflating and deflating the entry. See:
|
||||
// sun.tools.jar.Main.update()
|
||||
ZipEntry e2 = new ZipEntry(e1.getName());
|
||||
e2.setMethod(e1.getMethod());
|
||||
e2.setTime(e1.getTime());
|
||||
e2.setComment(e1.getComment());
|
||||
e2.setExtra(e1.getExtra());
|
||||
if (e1.getMethod() == ZipEntry.STORED) {
|
||||
e2.setSize(e1.getSize());
|
||||
e2.setCrc(e1.getCrc());
|
||||
}
|
||||
zos.putNextEntry(e2);
|
||||
zos.write(in.readAllBytes());
|
||||
zos.closeEntry();
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -987,6 +987,12 @@ public class JmodTask {
|
||||
recordHashes(in, jos, moduleHashes);
|
||||
jos.closeEntry();
|
||||
} else {
|
||||
// Setting "compressedSize" to "-1" prevents an error
|
||||
// in ZipOutputStream.closeEntry() if the newly
|
||||
// deflated entry will have another size than the
|
||||
// original compressed entry. See:
|
||||
// ZipOutputStream.putNextEntry()/closeEntry()
|
||||
e.setCompressedSize(-1);
|
||||
jos.putNextEntry(e);
|
||||
jos.write(in.readAllBytes());
|
||||
jos.closeEntry();
|
||||
|
Loading…
x
Reference in New Issue
Block a user