From b6a24b666a1c7536e35afaba4057cc8eac6fe48f Mon Sep 17 00:00:00 2001
Date: Thu, 21 Sep 2023 15:25:03 +0800
Subject: add 8146431-j.u.z.ZipFile.getEntry-throws-AIOOBE

---
 jdk/src/share/classes/java/util/zip/ZipFile.java | 2 +-
 jdk/test/java/util/zip/ZipFile/TestZipFile.java  | 9 ++++++++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/jdk/src/share/classes/java/util/zip/ZipFile.java b/jdk/src/share/classes/java/util/zip/ZipFile.java
index 38b642bdc..36135a9c0 100644
--- a/jdk/src/share/classes/java/util/zip/ZipFile.java
+++ b/jdk/src/share/classes/java/util/zip/ZipFile.java
@@ -1313,7 +1313,7 @@ class ZipFile implements ZipConstants, Closeable {
                     idx = getEntryNext(idx);
                 }
                 /* If not addSlash, or slash is already there, we are done */
-                if (!addSlash  || name[name.length - 1] == '/') {
+                if (!addSlash  || name.length == 0 || name[name.length - 1] == '/') {
                      return -1;
                 }
                 // Add a slash to the hash code
diff --git a/jdk/test/java/util/zip/ZipFile/TestZipFile.java b/jdk/test/java/util/zip/ZipFile/TestZipFile.java
index 30bae3bb9..773f47558 100644
--- a/jdk/test/java/util/zip/ZipFile/TestZipFile.java
+++ b/jdk/test/java/util/zip/ZipFile/TestZipFile.java
@@ -24,7 +24,7 @@
 
 /*
  * @test
- * @bug 8142508
+ * @bug 8142508 8146431
  * @summary Tests various ZipFile apis
  * @run main/manual TestZipFile
  */
@@ -230,6 +230,13 @@ public class TestZipFile {
     }
 
     static void doTest0(Zip zip, ZipFile zf) throws Throwable {
+        // (0) check zero-length entry name, no AIOOBE
+        try {
+            check(zf.getEntry("") == null);;
+        } catch (Throwable t) {
+            unexpected(t);
+	}
+
         List<ZipEntry> list = new ArrayList(zip.entries.keySet());
         // (1) check entry list, in expected order
         if (!check(Arrays.equals(
-- 
2.22.0

