adamhathcock/sharpcompress

WriteEntryToDirectory with GZipReader fails

edwardmjackson opened this issue · 4 comments

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

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 });
  }
}

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

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)

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