Skip to content

Commit b85500e

Browse files
author
Lance Andersen
committed
8276123: ZipFile::getEntry will not return a file entry when there is a directory entry of the same name within a Zip File
Reviewed-by: redestad, alanb
1 parent 0d2980c commit b85500e

File tree

2 files changed

+591
-5
lines changed

2 files changed

+591
-5
lines changed

src/java.base/share/classes/java/util/zip/ZipFile.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,13 +1631,18 @@ private int getEntryPos(String name, boolean addSlash) {
16311631
// slash
16321632
int entryLen = entry.length();
16331633
int nameLen = name.length();
1634-
if ((entryLen == nameLen && entry.equals(name)) ||
1635-
(addSlash &&
1636-
nameLen + 1 == entryLen &&
1637-
entry.startsWith(name) &&
1638-
entry.charAt(entryLen - 1) == '/')) {
1634+
if (entryLen == nameLen && entry.equals(name)) {
1635+
// Found our match
16391636
return pos;
16401637
}
1638+
// If addSlash is true we'll now test for name+/ providing
1639+
if (addSlash && nameLen + 1 == entryLen
1640+
&& entry.startsWith(name) &&
1641+
entry.charAt(entryLen - 1) == '/') {
1642+
// Found the entry "name+/", now find the CEN entry pos
1643+
int exactPos = getEntryPos(name, false);
1644+
return exactPos == -1 ? pos : exactPos;
1645+
}
16411646
} catch (IllegalArgumentException iae) {
16421647
// Ignore
16431648
}

0 commit comments

Comments
 (0)