Skip to content

Commit

Permalink
8276123: ZipFile::getEntry will not return a file entry when there is…
Browse files Browse the repository at this point in the history
… a directory entry of the same name within a Zip File

Reviewed-by: redestad, alanb
  • Loading branch information
Lance Andersen committed Nov 12, 2021
1 parent 0d2980c commit b85500e
Show file tree
Hide file tree
Showing 2 changed files with 591 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/java.base/share/classes/java/util/zip/ZipFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -1631,13 +1631,18 @@ private int getEntryPos(String name, boolean addSlash) {
// slash
int entryLen = entry.length();
int nameLen = name.length();
if ((entryLen == nameLen && entry.equals(name)) ||
(addSlash &&
nameLen + 1 == entryLen &&
entry.startsWith(name) &&
entry.charAt(entryLen - 1) == '/')) {
if (entryLen == nameLen && entry.equals(name)) {
// Found our match
return pos;
}
// If addSlash is true we'll now test for name+/ providing
if (addSlash && nameLen + 1 == entryLen
&& entry.startsWith(name) &&
entry.charAt(entryLen - 1) == '/') {
// Found the entry "name+/", now find the CEN entry pos
int exactPos = getEntryPos(name, false);
return exactPos == -1 ? pos : exactPos;
}
} catch (IllegalArgumentException iae) {
// Ignore
}
Expand Down

1 comment on commit b85500e

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.