Skip to content
Permalink
Browse files
8240333: jmod incorrectly updates .jar and .jmod files during hashing
Reviewed-by: martin, alanb, lancea
  • Loading branch information
Volker Simonis committed Mar 4, 2020
1 parent 128f083 commit ff843fabecf2722801a2ca3c4d95a47dca18ef1c
Showing with 22 additions and 3 deletions.
  1. +15 −2 src/jdk.jlink/share/classes/jdk/tools/jmod/JmodOutputStream.java
  2. +7 −1 src/jdk.jlink/share/classes/jdk/tools/jmod/JmodTask.java
@@ -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 @@ public void writeEntry(byte[] bytes, Section section, String path)
* 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 @@ private void updateModularJar(Path target, Path tempTarget,
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();

0 comments on commit ff843fa

Please sign in to comment.