Skip to content

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

Merged
yair100 merged 3 commits into
files-community:mainfrom
Lamparter:protected-names-extraction
Jun 9, 2026
Merged

Fix: Fixed an issue where archives with reserved item names wouldn't extract correctly#18070
yair100 merged 3 commits into
files-community:mainfrom
Lamparter:protected-names-extraction

Conversation

@Lamparter

Copy link
Copy Markdown
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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread src/Files.App/Actions/Content/Archives/Decompress/BaseDecompressArchiveAction.cs Outdated
@Lamparter Lamparter force-pushed the protected-names-extraction branch from a182e47 to b10666d Compare January 24, 2026 09:03
@Lamparter

Copy link
Copy Markdown
Contributor Author

@yaira2 requesting your review

@yair100

yair100 commented Jan 25, 2026

Copy link
Copy Markdown
Member

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
yair100
yair100 previously approved these changes Feb 17, 2026

@yair100 yair100 left a comment

Copy link
Copy Markdown
Member

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

@0x5bfa 0x5bfa left a comment

Copy link
Copy Markdown
Member

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;
}

@yair100 yair100 added changes requested Changes are needed for this pull request and removed ready to merge Pull requests that are approved and ready to merge labels Mar 16, 2026
@yair100

yair100 commented Apr 12, 2026

Copy link
Copy Markdown
Member

@Lamparter are you still planning to work on this? It's most of the way there but needs the changes @0x5bfa requested.

@Lamparter

Copy link
Copy Markdown
Contributor Author

I sent a comment on the discord server about an alternative solution but received no response, that's why this PR is stale
Either way, I will go with 0x5BFA's implementation for that method for now

@yair100

yair100 commented May 10, 2026

Copy link
Copy Markdown
Member

Can you please post the alternative solution here?

@Lamparter

Copy link
Copy Markdown
Contributor Author

A friend of mine suggested using ZLinq (which doesn't allocate memory at all) instead of Microsoft's System.Linq implementation (that allocates memory a lot)
https://github.com/Cysharp/ZLinq
It might also save performance elsewhere in the app if fully replaced

@yair100

yair100 commented May 11, 2026

Copy link
Copy Markdown
Member

I would like to avoid third party dependencies at this point.

Lamparter and others added 3 commits June 9, 2026 10:27
(just a general readability refactor, no impact made)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@yair100 yair100 force-pushed the protected-names-extraction branch from f8b0984 to a0bf0d0 Compare June 9, 2026 14:31
@yair100 yair100 added ready to merge Pull requests that are approved and ready to merge and removed changes requested Changes are needed for this pull request labels Jun 9, 2026
@yair100 yair100 requested a review from 0x5bfa June 9, 2026 14:46

@0x5bfa 0x5bfa left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, code wise.

@yair100 yair100 merged commit 65b6801 into files-community:main Jun 9, 2026
6 checks passed
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

4 participants