[PR #1037] [CLOSED] [WIP] Fix incomplete iteration of TarArchive entries #1463

Open
opened 2026-01-29 22:20:42 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/adamhathcock/sharpcompress/pull/1037
Author: @Copilot
Created: 11/25/2025
Status: Closed

Base: masterHead: copilot/fix-tararchive-incomplete-iteration


📝 Commits (3)

  • 27e6051 Initial plan
  • bfb8e94 Changes before error encountered
  • b83ee67 Add regression test for TarArchive.ExtractAllEntries()

📊 Changes

2 files changed (+25 additions, -1 deletions)

View changed files

📝 src/SharpCompress/Archives/AbstractArchive.cs (+1 -1)
📝 tests/SharpCompress.Test/Tar/TarArchiveTests.cs (+24 -0)

📄 Description

  • Understand the issue: TarArchive.ExtractAllEntries() fails because it's blocked by a check that only allows solid archives or 7Zip
  • Identify the root cause: The check if (!IsSolid && Type != ArchiveType.SevenZip) throws an exception for TAR archives
  • Fix: Modify the check to also allow TAR archives since TarArchive.CreateReaderForSolidExtraction() is implemented and works correctly
  • Add test to verify the fix
  • Run existing tests to ensure no regression
  • Run code review
  • Run CodeQL security check
Original prompt

This section details on the original issue you should resolve

<issue_title>Streaming TarArchive entries results in incomplete iteration</issue_title>
<issue_description>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.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/adamhathcock/sharpcompress/pull/1037 **Author:** [@Copilot](https://github.com/apps/copilot-swe-agent) **Created:** 11/25/2025 **Status:** ❌ Closed **Base:** `master` ← **Head:** `copilot/fix-tararchive-incomplete-iteration` --- ### 📝 Commits (3) - [`27e6051`](https://github.com/adamhathcock/sharpcompress/commit/27e6051241d8703e8f314f71daba7a3e031f3c89) Initial plan - [`bfb8e94`](https://github.com/adamhathcock/sharpcompress/commit/bfb8e9421ea6475029c06e5ae1d458a72bcad242) Changes before error encountered - [`b83ee67`](https://github.com/adamhathcock/sharpcompress/commit/b83ee67cdcb30a739a399774565b9278b5ab63b6) Add regression test for TarArchive.ExtractAllEntries() ### 📊 Changes **2 files changed** (+25 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `src/SharpCompress/Archives/AbstractArchive.cs` (+1 -1) 📝 `tests/SharpCompress.Test/Tar/TarArchiveTests.cs` (+24 -0) </details> ### 📄 Description - [x] Understand the issue: `TarArchive.ExtractAllEntries()` fails because it's blocked by a check that only allows solid archives or 7Zip - [x] Identify the root cause: The check `if (!IsSolid && Type != ArchiveType.SevenZip)` throws an exception for TAR archives - [x] Fix: Modify the check to also allow TAR archives since `TarArchive.CreateReaderForSolidExtraction()` is implemented and works correctly - [x] Add test to verify the fix - [x] Run existing tests to ensure no regression - [x] Run code review - [x] Run CodeQL security check <!-- START COPILOT CODING AGENT SUFFIX --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>Streaming TarArchive entries results in incomplete iteration</issue_title> > <issue_description>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.</issue_description> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> - Fixes adamhathcock/sharpcompress#1029 <!-- START COPILOT CODING AGENT TIPS --> --- 💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 22:20:42 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#1463