Skip to content

Fix: Fixed an issue where archives with reserved item names wouldn't extract correctly#18070

Open
Lamparter wants to merge 2 commits intofiles-community:mainfrom
Lamparter:protected-names-extraction
Open

Fix: Fixed an issue where archives with reserved item names wouldn't extract correctly#18070
Lamparter wants to merge 2 commits intofiles-community:mainfrom
Lamparter:protected-names-extraction

Conversation

@Lamparter
Copy link
Contributor

Resolved / Related Issues

Steps used to test these changes

  1. Opened Files
  2. Create an archive in a directory using tar --exclude=archive.tar -cf archive.tar . in Powershell
  3. Do the 'Extract (smart)' action on the newly created tar archive
  4. See that the folder '.' in the archive gets renamed to the archive name 'archive'

Copilot AI review requested due to automatic review settings January 17, 2026 12:12
@Lamparter Lamparter changed the title Fix "." and ".." in archives being extracted wrong Fix: Fixed an issue where archives with reserved item names wouldn't extract correctly Jan 17, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug where "." and ".." directory entries in archives were being incorrectly treated as meaningful top-level items during smart extraction. The fix ensures that when using "Extract (smart)" on archives containing "." (current directory) or ".." (parent directory) entries, these special directory references are properly ignored when determining whether to create a subfolder.

Changes:

  • Refactored the logic for detecting multiple top-level items in archives to filter out "." and ".." entries
  • Introduced a new helper function GetFirstMeaningfulSegment that skips special directory references when parsing archive entry paths

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Lamparter Lamparter force-pushed the protected-names-extraction branch from a182e47 to b10666d Compare January 24, 2026 09:03
@Lamparter
Copy link
Contributor Author

@yaira2 requesting your review

@yair100
Copy link
Member

yair100 commented Jan 25, 2026

Noted. I'd like to complete your earlier PRs before reviewing this one.

@yair100 yair100 added the ready for review Pull requests that are ready for review label Jan 25, 2026
@yair100 yair100 force-pushed the protected-names-extraction branch from f7d9b9c to f8b0984 Compare February 17, 2026 21:28
Copy link
Member

@yair100 yair100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm these changes are working as expected.

@yair100 yair100 requested a review from 0x5bfa February 17, 2026 21:34
@yair100 yair100 added ready to merge Pull requests that are approved and ready to merge and removed ready for review Pull requests that are ready for review labels Feb 17, 2026
Copy link
Member

@0x5bfa 0x5bfa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using LINQ isn't performant and allocates memory a lot.

Consider this.

static ReadOnlySpan<char> GetFirstMeaningfulSegment(ReadOnlySpan<char> path)
{
    while (!path.IsEmpty)
    {
        while (!path.IsEmpty && (path[0] == '/' || path[0] == '\\'))
            path = path[1..];

        if (path.IsEmpty) break;

        int sep = path.IndexOfAny('/', '\\');
        ReadOnlySpan<char> seg = sep < 0 ? path : path[..sep];

        path = sep < 0 ? ReadOnlySpan<char>.Empty : path[(sep + 1)..];

        if (seg.SequenceEqual("."u8) || seg.SequenceEqual(".."u8)) // Comparison of ASCII bytes
            continue;

        return seg;
    }

    return default;
}

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

Labels

ready to merge Pull requests that are approved and ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Smart extracting a .tar file with "." as the only directory in root is not properly handled

3 participants

Comments