WriteEntryToDirectory with GZipReader fails #628

Closed
opened 2026-01-29 22:14:55 +00:00 by claunia · 4 comments
Owner

Originally created by @edwardmjackson on GitHub (Apr 18, 2024).

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

Path.Combine throws an exception at 900190cf54/src/SharpCompress/Common/ExtractionMethods.cs (L60)

due to fileName being null, which is set here

900190cf54/src/SharpCompress/Common/ExtractionMethods.cs (L39)

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
Originally created by @edwardmjackson on GitHub (Apr 18, 2024). The generic extraction mechanism implemented in ExtractionMethods.cs appears to fail for GZip files. Path.Combine throws an exception at https://github.com/adamhathcock/sharpcompress/blob/900190cf54423ebc1187b647094b118881ab9485/src/SharpCompress/Common/ExtractionMethods.cs#L60 due to fileName being null, which is set here https://github.com/adamhathcock/sharpcompress/blob/900190cf54423ebc1187b647094b118881ab9485/src/SharpCompress/Common/ExtractionMethods.cs#L39 ``` 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 ```
Author
Owner

@edwardmjackson commented on GitHub (Apr 18, 2024):

As a follow up, this is probably a sketchy file header in the gzip file, looking at 900190cf54/src/SharpCompress/Common/GZip/GZipFilePart.cs (L94)

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 });
  }
}
@edwardmjackson commented on GitHub (Apr 18, 2024): As a follow up, this is probably a sketchy file header in the gzip file, looking at https://github.com/adamhathcock/sharpcompress/blob/900190cf54423ebc1187b647094b118881ab9485/src/SharpCompress/Common/GZip/GZipFilePart.cs#L94 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 }); } } ```
Author
Owner

@adamhathcock commented on GitHub (Apr 18, 2024):

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

@adamhathcock commented on GitHub (Apr 18, 2024): you're saying the entry.Key can be null?
Author
Owner

@edwardmjackson commented on GitHub (Apr 22, 2024):

Correct. The ! on this line

900190cf54/src/SharpCompress/Common/GZip/GZipFilePart.cs (L37)

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

@edwardmjackson commented on GitHub (Apr 22, 2024): Correct. The ! on this line https://github.com/adamhathcock/sharpcompress/blob/900190cf54423ebc1187b647094b118881ab9485/src/SharpCompress/Common/GZip/GZipFilePart.cs#L37 is masking it, but it can be null (in possibly wierdly-formed files that open fine in 7Zip)
Author
Owner

@adamhathcock commented on GitHub (Apr 23, 2024):

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

@adamhathcock commented on GitHub (Apr 23, 2024): 0.37.0 has fixed null support so maybe this isn't an issue now?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#628