Skip to content

Commit d02ac57

Browse files
author
Eirik Bjørsnøs
committed
8377983: (zipfs) ZipFileSystem.initCEN needlessly reads END header
Reviewed-by: lancea
1 parent a86a847 commit d02ac57

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2009, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -1233,7 +1233,7 @@ private void endRead() {
12331233

12341234
private volatile boolean isOpen = true;
12351235
private final SeekableByteChannel ch; // channel to the zipfile
1236-
final byte[] cen; // CEN & ENDHDR
1236+
final byte[] cen; // CEN
12371237
private END end;
12381238
private long locpos; // position of first LOC header (usually 0)
12391239

@@ -1585,15 +1585,15 @@ private byte[] initCEN() throws IOException {
15851585
if (locpos < 0)
15861586
throw new ZipException("invalid END header (bad central directory offset)");
15871587

1588-
// read in the CEN and END
1589-
byte[] cen = new byte[(int)(end.cenlen + ENDHDR)];
1590-
if (readNBytesAt(cen, 0, cen.length, cenpos) != end.cenlen + ENDHDR) {
1588+
// read in the CEN
1589+
byte[] cen = new byte[(int)(end.cenlen)];
1590+
if (readNBytesAt(cen, 0, cen.length, cenpos) != end.cenlen) {
15911591
throw new ZipException("read CEN tables failed");
15921592
}
15931593
// Iterate through the entries in the central directory
15941594
inodes = LinkedHashMap.newLinkedHashMap(end.centot + 1);
15951595
int pos = 0;
1596-
int limit = cen.length - ENDHDR;
1596+
int limit = cen.length;
15971597
while (pos < limit) {
15981598
if (!cenSigAt(cen, pos))
15991599
throw new ZipException("invalid CEN header (bad signature)");
@@ -1641,7 +1641,7 @@ private byte[] initCEN() throws IOException {
16411641
// skip ext and comment
16421642
pos += (CENHDR + nlen + elen + clen);
16431643
}
1644-
if (pos + ENDHDR != cen.length) {
1644+
if (pos != cen.length) {
16451645
throw new ZipException("invalid CEN header (bad header size)");
16461646
}
16471647
buildNodeTree();
@@ -1671,7 +1671,7 @@ private void checkExtraFields( byte[] cen, int cenPos, long size, long csize,
16711671
}
16721672
// CEN Offset where this Extra field ends
16731673
int extraEndOffset = startingOffset + extraFieldLen;
1674-
if (extraEndOffset > cen.length - ENDHDR) {
1674+
if (extraEndOffset > cen.length) {
16751675
zerror("Invalid CEN header (extra data field size too long)");
16761676
}
16771677
int currentOffset = startingOffset;

0 commit comments

Comments
 (0)