Skip to content

Commit 198aef4

Browse files
Yuri Nesterenkognu-andrew
authored andcommitted
8337494: Clarify JarInputStream behavior
Reviewed-by: mbalao, andrew Backport-of: 62c6b145614c1b6302ec8db153a7aa6dec1884bc
1 parent 13dab16 commit 198aef4

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
@@ -424,7 +424,8 @@ private Manifest getManifestFromReference() throws IOException {
424424
jv = new JarVerifier(manEntry.getName(), b);
425425
} else {
426426
if (JarVerifier.debug != null) {
427-
JarVerifier.debug.println("Multiple MANIFEST.MF found. Treat JAR file as unsigned");
427+
JarVerifier.debug.println(
428+
JarVerifier.MULTIPLE_MANIFEST_WARNING);
428429
}
429430
}
430431
}

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

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

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)