Skip to content

TarReader rejects GNU sparse 1.0 entries whose sparse map exceeds 1 KiB #134980

Description

@pawlos

Description

TarReader rejects valid GNU sparse format 1.0 (PAX) entries whose embedded sparse map is longer than about 1 KiB. Reading the entry's DataStream, or extracting it with TarFile.ExtractToDirectory, throws InvalidDataException: The TAR archive is corrupted or invalid.. GNU tar writes such maps for any moderately fragmented sparse file: a file with 76 data regions already produces a 1062-byte map.

Reproduction Steps

using System;
using System.Formats.Tar;
using System.IO;

// Both archives were written by tar (--format=pax --sparse --sparse-version=1.0).
foreach (string path in new[] { "sparse72.tar", "sparse76.tar" })
{
    string dir = Directory.CreateTempSubdirectory().FullName;
    try
    {
        TarFile.ExtractToDirectory(path, dir, overwriteFiles: true);
        Console.WriteLine($"{path}: OK");
    }
    catch (Exception ex)
    {
        Console.WriteLine($"{path}: {ex}");
    }
    finally
    {
        Directory.Delete(dir, recursive: true);
    }
}

sparse_files.zip

Expected behavior

Both archives are read and extracted without issues.

Actual behavior

InvalidDataException is thrown on a sparse file whose embedded sparse map is longer than about 1 KiB

Regression?

No. GNU sparse 1.0 reading is new in .NET 11

Known Workarounds

None

Configuration

.NET 11.0.0-rc.1.26425.128, linux-x64

Other information

  • Other implementations read both archives correctly: GNU tar, Python tarfile
  • The GNU sparse 1.0 format specification does not limit the sparse map size: https://www.gnu.org/software/tar/manual/html_node/PAX-1.html
  • The exception is thrown from GnuSparseStream.ParseSparseMapCoreAsync / ReadLineAsync.
  • Observed threshold: a 1006-byte sparse map (73 entries) works; a 1062-byte map (77 entries) fails.

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

    Labels

    area-System.IOuntriagedNew issue has not been triaged by the area owner

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions