Skip to content

Commit ef38a04

Browse files
Hai-May Chaojaikiran
authored andcommitted
8337494: Clarify JarInputStream behavior
Reviewed-by: jpai, rhalade, lancea
1 parent cf871db commit ef38a04

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
@@ -409,7 +409,8 @@ private Manifest getManifestFromReference() throws IOException {
409409
jv = new JarVerifier(manEntry.getName(), b);
410410
} else {
411411
if (JarVerifier.debug != null) {
412-
JarVerifier.debug.println("Multiple MANIFEST.MF found. Treat JAR file as unsigned");
412+
JarVerifier.debug.println(
413+
JarVerifier.MULTIPLE_MANIFEST_WARNING);
413414
}
414415
}
415416
}

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,17 @@ private JarEntry checkManifest(JarEntry e)
151151
jv = new JarVerifier(e.getName(), bytes);
152152
mev = new ManifestEntryVerifier(man, jv.manifestName);
153153
}
154-
return (JarEntry)super.getNextEntry();
154+
JarEntry nextEntry = (JarEntry)super.getNextEntry();
155+
if (nextEntry != null &&
156+
JarFile.MANIFEST_NAME.equalsIgnoreCase(nextEntry.getName())) {
157+
if (JarVerifier.debug != null) {
158+
JarVerifier.debug.println(JarVerifier.MULTIPLE_MANIFEST_WARNING);
159+
}
160+
161+
jv = null;
162+
mev = null;
163+
}
164+
return nextEntry;
155165
}
156166
return e;
157167
}

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, 2023, 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
@@ -46,6 +46,9 @@
4646
*/
4747
class JarVerifier {
4848

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

0 commit comments

Comments
 (0)