Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WriteEntryToDirectory with GZipReader fails #831

Closed
edwardmjackson opened this issue Apr 18, 2024 · 4 comments
Closed

WriteEntryToDirectory with GZipReader fails #831

edwardmjackson opened this issue Apr 18, 2024 · 4 comments

Comments

@edwardmjackson
Copy link

The generic extraction mechanism implemented in ExtractionMethods.cs appears to fail for GZip files.

Path.Combine throws an exception at

destinationFileName = Path.Combine(fullDestinationDirectoryPath, file);

due to fileName being null, which is set here

var file = Path.GetFileName(entry.Key);

StackTrace:
   at System.IO.Path.Combine(String path1, String path2) in System.IO\Path.cs:line 310
   at SharpCompress.Common.ExtractionMethods.WriteEntryToDirectory(IEntry entry, String destinationDirectory, ExtractionOptions options, Action`2 write) in SharpCompress.Common\ExtractionMethods.cs:line 44
   at SharpCompress.Readers.IReaderExtensions.WriteEntryToDirectory(IReader reader, String destinationDirectory, ExtractionOptions options) in SharpCompress.Readers\IReaderExtensions.cs:line 31
   at SharpCompress.Readers.IReaderExtensions.WriteAllToDirectory(IReader reader, String destinationDirectory, ExtractionOptions options) in SharpCompress.Readers\IReaderExtensions.cs:line 22
@edwardmjackson
Copy link
Author

As a follow up, this is probably a sketchy file header in the gzip file, looking at

_name = ReadZeroTerminatedString(_stream);

Trivial workaround for now:

using IReader reader = ReaderFactory.Open(sourceStream);

while (reader.MoveToNextEntry())
{
  if (!reader.Entry.IsDirectory)
  {
    reader.WriteEntryToFile(decompressedFileLocation, new ExtractionOptions { ExtractFullPath = false, Overwrite = true });
  }
}

@adamhathcock
Copy link
Owner

you're saying the entry.Key can be null?

@edwardmjackson
Copy link
Author

Correct. The ! on this line

internal override string FilePartName => _name!;

is masking it, but it can be null (in possibly wierdly-formed files that open fine in 7Zip)

@adamhathcock
Copy link
Owner

0.37.0 has fixed null support so maybe this isn't an issue now?

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

No branches or pull requests

2 participants