Skip to content

Streaming TarArchive entries results in incomplete iteration #1029

@DanTheMan827

Description

@DanTheMan827

Using the following code on this archive will result in incomplete iteration of the archive, and the exception being thrown

string desktopEntriesArchiveFile = Path.Combine(Path.Combine(Program.BaseDirectoryInternal, "data"), "desktop_entries.tar");

using (var extractor = TarArchive.Open(desktopEntriesArchiveFile))
{
    using (var reader = extractor.ExtractAllEntries())
    {
        var readEntries = 0;
        while (reader.MoveToNextEntry())
        {
            Trace.WriteLine($"Processing entry {readEntries++}: {reader.Entry.Key}");

            if (reader.Entry.IsDirectory)
                continue;

            using (var ms = new MemoryStream())
            {
                reader.WriteEntryTo(ms);
            }
        }

        if (readEntries != extractor.Entries.Count())
        {
            throw new Exception("Tar archive read entries count mismatch.");
        }
    }
}

This however, works fine.

string desktopEntriesArchiveFile = Path.Combine(Path.Combine(Program.BaseDirectoryInternal, "data"), "desktop_entries.tar");

using (var extractor = TarArchive.Open(desktopEntriesArchiveFile))
{
    var readEntries = 0;
    foreach (var entry in extractor.Entries)
    {
        Trace.WriteLine($"Processing entry {readEntries++}: {entry.Key}");

        if (entry.IsDirectory)
            continue;

        using (var ms = new MemoryStream())
        {
            entry.WriteTo(ms);
        }
    }

    if (readEntries != extractor.Entries.Count())
    {
        throw new Exception("Tar archive read entries count mismatch.");
    }
}

The archive was created on Windows using busybox tar

Using SharpCompress 0.41.0 with .NET 4.8

The issue does not occur with SharpCompress 0.40.0

Possibly related: Streamed gzip data fails to decompress due to checksum issue on 0.40, but fixed on latest.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions