Skip to content

Commit

Permalink
Fixed extractions after first ZIP64 entry is read from stream
Browse files Browse the repository at this point in the history
  • Loading branch information
pathartl committed Jun 22, 2024
1 parent 3eaac68 commit b7b78ed
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/SharpCompress/Common/Zip/StreamingZipHeaderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,17 @@ internal IEnumerable<ZipHeader> ReadStreamHeader(Stream stream)
reader = ((StreamingZipFilePart)_lastEntryHeader.Part).FixStreamedFileLocation(
ref rewindableStream
);

var pos = rewindableStream.CanSeek ? (long?)rewindableStream.Position : null;

headerBytes = reader.ReadUInt32();

var version = reader.ReadUInt16();
var flags = (HeaderFlags)reader.ReadUInt16();
var compressionMethod = (ZipCompressionMethod)reader.ReadUInt16();
var lastModifiedTime = reader.ReadUInt16();
var lastModifiedDate = reader.ReadUInt16();

var crc = reader.ReadUInt32();
if (crc == POST_DATA_DESCRIPTOR)
{
Expand All @@ -62,7 +72,6 @@ ref rewindableStream
var uncompressed_size = reader.ReadUInt32();

// Check if we have header or 64bit DataDescriptor
headerBytes = reader.ReadUInt32();
var test_header = !(headerBytes == 0x04034b50 || headerBytes == 0x02014b50);

var test_64bit = ((long)uncompressed_size << 32) | compressed_size;
Expand All @@ -80,6 +89,9 @@ ref rewindableStream
if (pos.HasValue)
{
_lastEntryHeader.DataStartPosition = pos - _lastEntryHeader.CompressedSize;

// 4 = First 4 bytes of the entry header (i.e. 50 4B 03 04)
rewindableStream.Position = pos.Value + 4;
}
}
else
Expand Down

0 comments on commit b7b78ed

Please sign in to comment.