Streaming TarArchive entries results in incomplete iteration #725

Open
opened 2026-01-29 22:16:28 +00:00 by claunia · 1 comment
Owner

Originally created by @DanTheMan827 on GitHub (Nov 20, 2025).

Originally assigned to: @Copilot on GitHub.

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.

Originally created by @DanTheMan827 on GitHub (Nov 20, 2025). Originally assigned to: @Copilot on GitHub. Using the following code on [this archive](https://gist.github.com/DanTheMan827/5a56c5ff239e0ce0b0b228da155f78a6/raw/c709cf692fd49aeda903eaa7f63d90dbfa604ef7/desktop_entries.tar) will result in incomplete iteration of the archive, and the exception being thrown ```c# 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. ```c# 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.
Author
Owner

@Morilli commented on GitHub (Nov 29, 2025):

This was fixed with #1017.

@Morilli commented on GitHub (Nov 29, 2025): This was fixed with #1017.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#725