Skip to content

Commit 901c03c

Browse files
committed
Fix JvmZipReaderStrategy using 0 as fallback start offset, instead of first PK match, preventing it from working on files with bogus header data
1 parent 92d708a commit 901c03c

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/main/java/software/coley/llzip/format/read/JvmZipReaderStrategy.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,7 @@ public void read(ZipArchive zip, ByteData data) throws IOException {
6060
// Determine base offset for computing file header locations with.
6161
// - If there is a preceding block of another zip, start with that.
6262
long jvmBaseFileOffset;
63-
if (precedingEndOfCentralDirectory == endOfCentralDirectoryOffset) {
64-
// The prior end part match is target end part, so we can't use it as a base offset.
65-
jvmBaseFileOffset = 0L;
66-
} else if (precedingEndOfCentralDirectory == -1L) {
63+
if (precedingEndOfCentralDirectory == -1L) {
6764
// There was no match for a prior end part. We will seek forwards until finding a *VALID* PK starting header.
6865
jvmBaseFileOffset = ByteDataUtil.indexOf(data, ZipPatterns.PK);
6966
while (jvmBaseFileOffset >= 0L) {
@@ -100,8 +97,8 @@ else if (ByteDataUtil.startsWith(data, jvmBaseFileOffset, ZipPatterns.CENTRAL_DI
10097
// - Needs to be done in such a way where we do not get tricked by the '-trick.jar' samples
10198
jvmBaseFileOffset = precedingEndOfCentralDirectory + tempEnd.length();
10299
} catch (Exception ex) {
103-
// It's bogus and the sig-match was a coincidence. Zero out the offset.
104-
jvmBaseFileOffset = 0;
100+
// It's bogus and the sig-match was a coincidence. Use the first PK match instead.
101+
jvmBaseFileOffset = ByteDataUtil.indexOf(data, ZipPatterns.PK);
105102
}
106103
}
107104

0 commit comments

Comments
 (0)