8146431: j.u.z.ZipFile.getEntry("") throws AIOOBE
authorsherman
Mon, 04 Jan 2016 14:34:53 -0800
changeset 34874 55a62be87e89
parent 34873 5696afb07ba3
child 34875 ac52689ae546
8146431: j.u.z.ZipFile.getEntry("") throws AIOOBE Reviewed-by: lancea
jdk/src/java.base/share/classes/java/util/zip/ZipFile.java
jdk/test/java/util/zip/ZipFile/TestZipFile.java
--- a/jdk/src/java.base/share/classes/java/util/zip/ZipFile.java	Mon Jan 04 12:25:45 2016 -0500
+++ b/jdk/src/java.base/share/classes/java/util/zip/ZipFile.java	Mon Jan 04 14:34:53 2016 -0800
@@ -1251,7 +1251,7 @@
                     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 slash and try once more */
--- a/jdk/test/java/util/zip/ZipFile/TestZipFile.java	Mon Jan 04 12:25:45 2016 -0500
+++ b/jdk/test/java/util/zip/ZipFile/TestZipFile.java	Mon Jan 04 14:34:53 2016 -0800
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8142508
+ * @bug 8142508 8146431
  * @summary Tests various ZipFile apis
  * @run main/manual TestZipFile
  */
@@ -216,6 +216,13 @@
     }
 
     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(