diff --git a/SharpCompress/Archive/Zip/ZipArchive.cs b/SharpCompress/Archive/Zip/ZipArchive.cs index 61a5e3f8..9b30a37f 100644 --- a/SharpCompress/Archive/Zip/ZipArchive.cs +++ b/SharpCompress/Archive/Zip/ZipArchive.cs @@ -116,7 +116,7 @@ namespace SharpCompress.Archive.Zip try { ZipHeader header = - headerFactory.ReadStreamHeader(stream).FirstOrDefault(x => x.ZipHeaderType != ZipHeaderType.Split); + headerFactory.ReadStreamHeader(stream).FirstOrDefault(x => x != null && x.ZipHeaderType != ZipHeaderType.Split); if (header == null) { return false; diff --git a/SharpCompress/Common/Zip/StreamingZipHeaderFactory.cs b/SharpCompress/Common/Zip/StreamingZipHeaderFactory.cs index 6bcffa1d..c9f1e182 100644 --- a/SharpCompress/Common/Zip/StreamingZipHeaderFactory.cs +++ b/SharpCompress/Common/Zip/StreamingZipHeaderFactory.cs @@ -45,18 +45,17 @@ namespace SharpCompress.Common.Zip lastEntryHeader = null; uint headerBytes = reader.ReadUInt32(); header = ReadHeader(headerBytes, reader); - - //entry could be zero bytes so we need to know that. - if (header.ZipHeaderType == ZipHeaderType.LocalEntry) - { - bool isRecording = rewindableStream.IsRecording; - if (!isRecording) - { - rewindableStream.StartRecording(); + if (header != null) { + // entry could be zero bytes so we need to know that. + if(header.ZipHeaderType == ZipHeaderType.LocalEntry) { + bool isRecording = rewindableStream.IsRecording; + if (!isRecording) { + rewindableStream.StartRecording(); + } + uint nextHeaderBytes = reader.ReadUInt32(); + header.HasData = !IsHeader(nextHeaderBytes); + rewindableStream.Rewind(!isRecording); } - uint nextHeaderBytes = reader.ReadUInt32(); - header.HasData = !IsHeader(nextHeaderBytes); - rewindableStream.Rewind(!isRecording); } yield return header; } diff --git a/SharpCompress/Common/Zip/ZipHeaderFactory.cs b/SharpCompress/Common/Zip/ZipHeaderFactory.cs index 842d77b8..f6281738 100644 --- a/SharpCompress/Common/Zip/ZipHeaderFactory.cs +++ b/SharpCompress/Common/Zip/ZipHeaderFactory.cs @@ -87,7 +87,7 @@ namespace SharpCompress.Common.Zip return entry; } default: - throw new NotSupportedException("Unknown header: " + headerBytes); + return null; } }