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

Closed
opened 2026-01-29 22:16:07 +00:00 by claunia · 1 comment
Owner

Originally created by @mitchcapper on GitHub (Sep 11, 2025).

Right now factories are just bruteforced in order when detecting an unknown stream. While things can have the wrong extension or the user may not know the extension I would assume a good bit of time the user does have the filename.

The user could optionally provide this for hinting. We already maintain a list of supported extensions for external use ( IFactory.GetSupportedExtensions ) that we could then make use of internally. This would be largely backwards compatible as we would simply switch which factory we try first to be the suspected factory, if that fails the normal bruting of the other factories would be used. Things like TarFactory could use the ReaderOptions extension to even decide what compression algorithm to try first (although that would require adding an internal table of extension to compression alg as I don't think we maintain that data anywhere).

If this sounds sane I can do a PR.

Originally created by @mitchcapper on GitHub (Sep 11, 2025). Right now factories are just bruteforced in order when detecting an unknown stream. While things can have the wrong extension or the user may not know the extension I would assume a good bit of time the user does have the filename. The user could optionally provide this for hinting. We already maintain a list of supported extensions for external use ( IFactory.GetSupportedExtensions ) that we could then make use of internally. This would be largely backwards compatible as we would simply switch which factory we try first to be the suspected factory, if that fails the normal bruting of the other factories would be used. Things like TarFactory could use the ReaderOptions extension to even decide what compression algorithm to try first (although that would require adding an internal table of extension to compression alg as I don't think we maintain that data anywhere). If this sounds sane I can do a PR.
claunia added the enhancementup for grabs labels 2026-01-29 22:16:07 +00:00
Author
Owner

@adamhathcock commented on GitHub (Sep 15, 2025):

It's sane but it's a convenience thing. I'm happy to accept PRs but generally don't do them myself as I just thought others would do their own as this is a low level library. There have been vulnerabilities related to the extras (like creating directories) instead of the core of the library.

That said, I'm happy to accept PRs about anything really.

@adamhathcock commented on GitHub (Sep 15, 2025): It's sane but it's a convenience thing. I'm happy to accept PRs but generally don't do them myself as I just thought others would do their own as this is a low level library. There have been vulnerabilities related to the extras (like creating directories) instead of the core of the library. That said, I'm happy to accept PRs about anything really.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#701