Skip to content

Commit 2561a40

Browse files
committed
fix: Additional bogus checks in JVM read strategy
Just temporary measures until the associated TODO message is properly addressed.
1 parent 3553284 commit 2561a40

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>software.coley</groupId>
88
<artifactId>lljzip</artifactId>
9-
<version>1.1.6</version>
9+
<version>1.1.7</version>
1010

1111
<properties>
1212
<junit.version>5.8.2</junit.version>

src/main/java/software/coley/llzip/strategy/JvmZipReaderStrategy.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,25 @@ else if (ByteDataUtil.startsWith(data, jvmBaseFileOffset, ZipPatterns.CENTRAL_DI
7878
}
7979
}
8080
} else {
81-
// TODO: Double check 'precedingEndOfCentralDirectory' points to a EndOfCentralDirectory that isn't bogus
82-
// like some shit defined as a fake comment in another ZipPart
83-
8481
// There was a prior end part, so we will seek past it's length and use that as the base offset.
8582
try {
8683
// Make sure it isn't bogus before we use it as a reference point
8784
EndOfCentralDirectory tempEnd = new EndOfCentralDirectory();
8885
tempEnd.read(data, precedingEndOfCentralDirectory);
86+
87+
88+
// TODO: Double check 'precedingEndOfCentralDirectory' points to a EndOfCentralDirectory that isn't bogus
89+
// like some shit defined as a fake comment in another ZipPart.
90+
// - Needs to be done in such a way where we do not get tricked by the '-trick.jar' samples
91+
// This is a quick hack.
92+
if (tempEnd.getCentralDirectorySize() > len)
93+
throw new IllegalStateException();
94+
if (tempEnd.getCentralDirectoryOffset() > tempEnd.getNumEntries())
95+
throw new IllegalStateException();
96+
if (tempEnd.getDiskNumber() == 0 && tempEnd.getNumEntries() != tempEnd.getCentralDirectoryOffset())
97+
throw new IllegalStateException();
98+
99+
89100
jvmBaseFileOffset = precedingEndOfCentralDirectory + tempEnd.length();
90101
} catch (Exception ex) {
91102
// It's bogus and the sig-match was a coincidence. Zero out the offset.

0 commit comments

Comments
 (0)