From b8660a9215cee8d1a956f2eb624722d91478db64 Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 21 Jul 2024 04:09:27 -0400 Subject: [PATCH] Double check the general purpose bit flag isn't lying to us when using JvmLFH --- pom.xml | 2 +- .../lljzip/format/model/JvmLocalFileHeader.java | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index c53b5cf..18488c9 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ software.coley lljzip - 2.6.0 + 2.6.1 LL Java ZIP Lower level ZIP support for Java diff --git a/src/main/java/software/coley/lljzip/format/model/JvmLocalFileHeader.java b/src/main/java/software/coley/lljzip/format/model/JvmLocalFileHeader.java index 5ecd074..7994422 100644 --- a/src/main/java/software/coley/lljzip/format/model/JvmLocalFileHeader.java +++ b/src/main/java/software/coley/lljzip/format/model/JvmLocalFileHeader.java @@ -60,9 +60,16 @@ public void read(@Nonnull MemorySegment data, long offset) { // // The JVM technically allows the header to be excluded, so we split the offset fixing // into two parts. - absoluteDataOffsetEnd -= 12; - if (MemorySegmentUtil.readQuad(data, absoluteDataOffsetEnd) == ZipPatterns.DATA_DESCRIPTOR_QUAD) { - absoluteDataOffsetEnd -= 4; + // + // In some WEIRD cases the bit flag can be set, but the data-descriptor will be missing. + // When this occurs we can validate the range is currently correct by checking if the data end offset + // is the beginning of another file header. If we find the file header, the bit flag is a lie, + // and we do not need to manipulate our data end offset. + if ((MemorySegmentUtil.readWord(data, absoluteDataOffsetEnd) & ZipPatterns.PK_WORD) != ZipPatterns.PK_WORD) { + absoluteDataOffsetEnd -= 12; + if (MemorySegmentUtil.readQuad(data, absoluteDataOffsetEnd) == ZipPatterns.DATA_DESCRIPTOR_QUAD) { + absoluteDataOffsetEnd -= 4; + } } } relativeDataOffsetEnd = absoluteDataOffsetEnd == null ? relativeDataOffsetStart : absoluteDataOffsetEnd - offset;