Skip to content

TarFile.ExtractToDirectory() doesn't work sometimes with compressed archives #74242

Description

@iSazonov

Description

TarFile.ExtractToDirectoryInternal() doesn't work with some compressed archives.

The method works in examples from tests of the repo.
But it doesn't work if I try an archive created with 7-Zip or official PowerShell distributive (link is below).

If I try TarReader on the same archives I can read all entries.

Also the method works well if an archive is not compressed.

Small example archives created with 7-Zip
examples.zip

Reproduction Steps

  1. Download https://github.com/PowerShell/PowerShell/releases/download/v7.3.0-preview.6/powershell-7.3.0-preview.6-linux-x64.tar.gz
  2. Try read with simple code:
            using (var sourceStream = File.OpenRead(args[0]))
            using (var decompressorStream = new GZipStream(sourceStream, CompressionMode.Decompress))
            {
                TarFile.ExtractToDirectory(decompressorStream, args[1], true);
            }

Expected behavior

The archive is unpacked well.

Actual behavior

Exception throws:

Unhandled exception. System.FormatException: Could not find any recognizable digits.                                                                      at System.ParseNumbers.StringToInt(ReadOnlySpan`1 s, Int32 radix, Int32 flags, Int32& currPos)                                                         at System.Convert.ToInt32(String value, Int32 fromBase)                                                                                                at System.Formats.Tar.TarHelpers.GetTenBaseNumberFromOctalAsciiChars(Span`1 buffer)                                                                    at System.Formats.Tar.TarHeader.TryReadCommonAttributes(Span`1 buffer)                                                                                 at System.Formats.Tar.TarHeader.TryGetNextHeader(Stream archiveStream, Boolean copyData)                                                               at System.Formats.Tar.TarReader.TryGetNextEntryHeader(TarHeader& header, Boolean copyData)                                                             at System.Formats.Tar.TarReader.GetNextEntry(Boolean copyData)                                                                                         at System.Formats.Tar.TarFile.ExtractToDirectoryInternal(Stream source, String destinationDirectoryPath, Boolean overwriteFiles, Boolean leaveOpen)

Regression?

No response

Known Workarounds

No response

Configuration

.Net Preview.7

Other information

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions