Skip to content

Commit b8660a9

Browse files
committed
Double check the general purpose bit flag isn't lying to us when using JvmLFH
1 parent cd3551a commit b8660a9

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-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>2.6.0</version>
9+
<version>2.6.1</version>
1010

1111
<name>LL Java ZIP</name>
1212
<description>Lower level ZIP support for Java</description>

src/main/java/software/coley/lljzip/format/model/JvmLocalFileHeader.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,16 @@ public void read(@Nonnull MemorySegment data, long offset) {
6060
//
6161
// The JVM technically allows the header to be excluded, so we split the offset fixing
6262
// into two parts.
63-
absoluteDataOffsetEnd -= 12;
64-
if (MemorySegmentUtil.readQuad(data, absoluteDataOffsetEnd) == ZipPatterns.DATA_DESCRIPTOR_QUAD) {
65-
absoluteDataOffsetEnd -= 4;
63+
//
64+
// In some WEIRD cases the bit flag can be set, but the data-descriptor will be missing.
65+
// When this occurs we can validate the range is currently correct by checking if the data end offset
66+
// is the beginning of another file header. If we find the file header, the bit flag is a lie,
67+
// and we do not need to manipulate our data end offset.
68+
if ((MemorySegmentUtil.readWord(data, absoluteDataOffsetEnd) & ZipPatterns.PK_WORD) != ZipPatterns.PK_WORD) {
69+
absoluteDataOffsetEnd -= 12;
70+
if (MemorySegmentUtil.readQuad(data, absoluteDataOffsetEnd) == ZipPatterns.DATA_DESCRIPTOR_QUAD) {
71+
absoluteDataOffsetEnd -= 4;
72+
}
6673
}
6774
}
6875
relativeDataOffsetEnd = absoluteDataOffsetEnd == null ? relativeDataOffsetStart : absoluteDataOffsetEnd - offset;

0 commit comments

Comments
 (0)