8337494: Clarify JarInputStream behavior

Backport-of: 353f6e90bec7248016b2c733bae52ed6ca06fc20
This commit is contained in:
Nibedita Jena
2025-01-13 07:26:07 +00:00
committed by Sergey Shelomentsev
parent b7a165efd6
commit 056e46f364
3 changed files with 17 additions and 3 deletions

View File

@@ -421,7 +421,8 @@ public class JarFile extends ZipFile {
jv = new JarVerifier(manEntry.getName(), b);
} else {
if (JarVerifier.debug != null) {
JarVerifier.debug.println("Multiple MANIFEST.MF found. Treat JAR file as unsigned");
JarVerifier.debug.println(
JarVerifier.MULTIPLE_MANIFEST_WARNING);
}
}
}

View File

@@ -146,7 +146,17 @@ public class JarInputStream extends ZipInputStream {
jv = new JarVerifier(e.getName(), bytes);
mev = new ManifestEntryVerifier(man, jv.manifestName);
}
return (JarEntry)super.getNextEntry();
JarEntry nextEntry = (JarEntry)super.getNextEntry();
if (nextEntry != null &&
JarFile.MANIFEST_NAME.equalsIgnoreCase(nextEntry.getName())) {
if (JarVerifier.debug != null) {
JarVerifier.debug.println(JarVerifier.MULTIPLE_MANIFEST_WARNING);
}
jv = null;
mev = null;
}
return nextEntry;
}
return e;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2024, 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
@@ -46,6 +46,9 @@ import static sun.security.util.SignatureFileVerifier.isInMetaInf;
*/
class JarVerifier {
public static final String MULTIPLE_MANIFEST_WARNING =
"WARNING: Multiple MANIFEST.MF found. Treat JAR file as unsigned.";
/* Are we debugging ? */
static final Debug debug = Debug.getInstance("jar");