Skip to content

Commit 25d9c74

Browse files
Yuri NesterenkoRealCLanger
authored andcommitted
8337494: Clarify JarInputStream behavior
Reviewed-by: mbalao Backport-of: 353f6e90bec7248016b2c733bae52ed6ca06fc20
1 parent 58e97dd commit 25d9c74

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

src/java.base/share/classes/java/util/jar/JarFile.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,8 @@ private Manifest getManifestFromReference() throws IOException {
422422
jv = new JarVerifier(manEntry.getName(), b);
423423
} else {
424424
if (JarVerifier.debug != null) {
425-
JarVerifier.debug.println("Multiple MANIFEST.MF found. Treat JAR file as unsigned");
425+
JarVerifier.debug.println(
426+
JarVerifier.MULTIPLE_MANIFEST_WARNING);
426427
}
427428
}
428429
}

src/java.base/share/classes/java/util/jar/JarInputStream.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,17 @@ private JarEntry checkManifest(JarEntry e)
9797
jv = new JarVerifier(e.getName(), bytes);
9898
mev = new ManifestEntryVerifier(man, jv.manifestName);
9999
}
100-
return (JarEntry)super.getNextEntry();
100+
JarEntry nextEntry = (JarEntry)super.getNextEntry();
101+
if (nextEntry != null &&
102+
JarFile.MANIFEST_NAME.equalsIgnoreCase(nextEntry.getName())) {
103+
if (JarVerifier.debug != null) {
104+
JarVerifier.debug.println(JarVerifier.MULTIPLE_MANIFEST_WARNING);
105+
}
106+
107+
jv = null;
108+
mev = null;
109+
}
110+
return nextEntry;
101111
}
102112
return e;
103113
}

src/java.base/share/classes/java/util/jar/JarVerifier.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -44,6 +44,9 @@
4444
*/
4545
class JarVerifier {
4646

47+
public static final String MULTIPLE_MANIFEST_WARNING =
48+
"WARNING: Multiple MANIFEST.MF found. Treat JAR file as unsigned.";
49+
4750
/* Are we debugging ? */
4851
static final Debug debug = Debug.getInstance("jar");
4952

0 commit comments

Comments
 (0)