mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-04-05 21:51:09 +00:00
Skipping entries with InvalidFormatException #516
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @pgodwin on GitHub (Apr 15, 2022).
Firstly, thanks for such an terrific library!
Quick question - is it possible to skip entries with an InvalidFormatException?
I have some rar files (comicbook CBR files), that seem to have been corrupted. WinRar will skip over those files, but SharpCompress throws an
SharpCompress.Common.InvalidFormatException: 'Unknown Rar Header: 205'exception.It seems to happen on the MoveNext() of the Entries enumerator.
@adamhathcock commented on GitHub (Apr 19, 2022):
SharpComrpess is more raw than WinRAR. You'll have to manually try/catch errors like that.
If there's a better way to handle corrupt entries and skip them, I'm open to changing the API.
@pgodwin commented on GitHub (Apr 20, 2022):
Strangely, if I call to
RarArchive.Entries.Count, before looping through the entries, the exception isn't raised.@adamhathcock commented on GitHub (Apr 20, 2022):
The entries are built only using the header that has file info then skips to the next header without reading everything.
It's likely that a file is stored/compressed incorrectly but the recorded sizes are fine.
@pgodwin commented on GitHub (Apr 20, 2022):
I think thats it. I tried creating some purposefully corrupted RAR files to try and reproduce the issue, but couldn't reproduce the issue (only ended up creating invalid vints or changing the number of bytes in the file).
I'm happy to close this issue as it's clearly by design and isn't a bug in the code.
At this point, I don't have any API suggestions to improve things - it'd be good to know if an entry is invalid or can't be read, and be able to skip to the next item - but how you would do so cleanly I'm not too sure (perhaps overload
IEnumerator.MoveNext()with an option to ignore bad entries / add an State/Exception field to the collection).@adamhathcock commented on GitHub (Apr 21, 2022):
Yeah, the problem is that you can only "detect" it by trying to decompress the file. Putting a try/catch in the correct place is the trick but doing it in a clean way is the hard part.