Repository navigation
Better handling of Zip files without a valid signature found - #1479
Conversation
|
Thank-you for the submission. I'm not opposed to making a change like this, but I think there is a better way to do it. First, I have to ask why this is necessary - what application or library is creating zip files without a valid zip signature? I don't think this has ever come up before in dnGrep. Second, you made this change in one place, ArchiveEngine.SearchInsideArchive. There are three other places in the dnGrep code that are using the same SevenZipExtractor constructor: ArchiveDirectory.EnumerateFiles, ArchiveDirectory.GetLinesWithContext, and ArchiveDirectory.ExtractToTempFile. Wouldn't those methods also need to check the file name when the signature fails? I think it would be better to leave calling the FileChecker code in the SevenZip library and not copy it to each of these callers. I would add a new SevenZipExtactor constructor that takes the archive name in addition to the stream: Then add an optional parameter to the Init method: And add a new CheckSignature method to FileChecker that takes both a file name and a stream: GetLinesWithContext and ExtractToTempFile do not currently have the archive file name, it will have to be passed down the calling tree. |
|
I applied these changes |
|
Thank-you. I'm merging this pull request. I think you missed my second comment above: this change should also be applied to the ArchiveDirectory class. I'll add another PR to make those changes |
The goal of the PR is to fix this error in Grep_Error_Log.xml
Failed to search inside archive 'C:\PROJECTS\client.zip' System.ArgumentException: The stream is invalid or no corresponding signature was found. at SevenZip.FileChecker.CheckSignature(Stream stream, Int32& offset, Boolean& isExecutable) in C:\Users\tbernard\source\repos\dnGrep\SevenZip\FileChecker.cs:line 230 at SevenZip.SevenZipExtractor.Init(Stream stream, Boolean leaveOpen) in C:\Users\tbernard\source\repos\dnGrep\SevenZip\SevenZipExtractor.cs:line 113 at SevenZip.SevenZipExtractor..ctor(Stream archiveStream, String password, Boolean leaveOpen) in C:\Users\tbernard\source\repos\dnGrep\SevenZip\SevenZipExtractor.cs:line 238 at dnGREP.Engines.ArchiveEngine.SearchInsideArchive(Stream input, String fileName, String password, String searchPattern, SearchType searchType, GrepSearchOption searchOptions, Encoding encoding, PauseCancelToken pauseCancelToken)+MoveNext() in C:\Users\tbernard\source\repos\dnGrep\dnGREP.Engines\ArchiveEngine.cs:line 141 at dnGREP.Engines.ArchiveEngine.Search(Stream input, String fileName, String password, String searchPattern, SearchType searchType, GrepSearchOption searchOptions, Encoding encoding, PauseCancelToken pauseCancelToken)+MoveNext() in C:\Users\tbernard\source\repos\dnGrep\dnGREP.Engines\ArchiveEngine.cs:line 108What changed and why
Before
new SevenZipExtractor(input, password, true) — format guessed from stream only
After
Format is resolved first with the same try/catch fallback to extension that the string constructor uses
Before
ArgumentException propagates when no signature matches
After
Falls back to Formats.FormatByFileName(fileName, true) using the known fileName
Before
Uses the (Stream, string, bool) overload which calls CheckSignature(Stream) internally
After
Uses the (Stream, InArchiveFormat, bool) / (Stream, string, InArchiveFormat, bool) overload which skips CheckSignature entirely