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
This commit is contained in:
Lance Andersen 2021-11-12 17:12:13 +00:00
parent 0d2980cdd1
commit b85500e524
2 changed files with 591 additions and 5 deletions

View file

@ -1631,13 +1631,18 @@ public class ZipFile implements ZipConstants, Closeable {
// 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
}