mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 14:24:46 +02:00
8341625: Improve ZipFile validation of the END header
Reviewed-by: lancea
This commit is contained in:
parent
e704c055a4
commit
950e3a7587
2 changed files with 152 additions and 17 deletions
|
@ -1605,7 +1605,7 @@ public class ZipFile implements ZipConstants, Closeable {
|
|||
|
||||
|
||||
private static class End {
|
||||
int centot; // 4 bytes
|
||||
long centot; // 4 bytes
|
||||
long cenlen; // 4 bytes
|
||||
long cenoff; // 4 bytes
|
||||
long endpos; // 4 bytes
|
||||
|
@ -1697,7 +1697,7 @@ public class ZipFile implements ZipConstants, Closeable {
|
|||
// to use the end64 values
|
||||
end.cenlen = cenlen64;
|
||||
end.cenoff = cenoff64;
|
||||
end.centot = (int)centot64; // assume total < 2g
|
||||
end.centot = centot64;
|
||||
end.endpos = end64pos;
|
||||
} catch (IOException x) {} // no ZIP64 loc/end
|
||||
return end;
|
||||
|
@ -1733,11 +1733,14 @@ public class ZipFile implements ZipConstants, Closeable {
|
|||
if (end.cenlen > MAX_CEN_SIZE) {
|
||||
zerror("invalid END header (central directory size too large)");
|
||||
}
|
||||
if (end.centot < 0 || end.centot > end.cenlen / CENHDR) {
|
||||
zerror("invalid END header (total entries count too large)");
|
||||
}
|
||||
cen = this.cen = new byte[(int)end.cenlen];
|
||||
if (readFullyAt(cen, 0, cen.length, cenpos) != end.cenlen) {
|
||||
zerror("read CEN tables failed");
|
||||
}
|
||||
this.total = end.centot;
|
||||
this.total = Math.toIntExact(end.centot);
|
||||
} else {
|
||||
cen = this.cen;
|
||||
this.total = knownTotal;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue