Skip to content

Conversation

@mitchcapper
Copy link
Contributor

Also used by TarFactory to hint what compressiontype to attempt first

Close #942

This adds extension hinting support to ReaderFactory and allows compressors to optionally use the hinting as well for their own prioritization.

This only prioritizes which factories/methods we try first so should not result in a change of functionality for anyone (it also only does the prioritization if you provide the extension as a hint).

I added prioritization to tar as well, this required rewriting it a bit but it allowed removing a good bit of duplicate code. I don't know why certain tar methods require wrapping the rewind stream again, would seem this maybe should be a property on the type, but I did preserve this functionality.

I added gzip to TarFactory as well. While the GzipFactory would eventually handle it from brute force it seemed like it belonged in TarFactory with the others.

For bare tar archives I no longer use TarReader.Open as it has redundant code once again brute forcing the compression types. Given the code path was only triggered if the IsTarFile check passed before even if they were slightly different it shouldn't matter.

I don't think this introduces much of a different code path that could be exploited but the tar change would probably be the biggest.

This makes it a bit easier to track 'legitimate' exceptions in the library when debugging vs ones caused during the type brute forcing.

Also used by TarFactory to hint what compressiontype to attempt first
Copy link
Owner

@adamhathcock adamhathcock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks interesting, thanks!

Was this causing perf issues for you?

@mitchcapper
Copy link
Contributor Author

No more so trying to debug sharp compress some of the exceptions types thrown were too generic to just ignore for the entire library but would always occur at startup when it bruted some of the formats.

@adamhathcock adamhathcock merged commit fb2cdda into adamhathcock:master Sep 29, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

optional smarter readerfactory testing through readeroptions adding an extension or ArchiveType for hinting?

2 participants