Fix: Fixed an issue where archives with reserved item names wouldn't extract correctly#18070
Fix: Fixed an issue where archives with reserved item names wouldn't extract correctly#18070Lamparter wants to merge 2 commits intofiles-community:mainfrom
Conversation
There was a problem hiding this comment.
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
GetFirstMeaningfulSegmentthat skips special directory references when parsing archive entry paths
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/Files.App/Actions/Content/Archives/Decompress/BaseDecompressArchiveAction.cs
Outdated
Show resolved
Hide resolved
a182e47 to
b10666d
Compare
|
@yaira2 requesting your review |
|
Noted. I'd like to complete your earlier PRs before reviewing this one. |
(just a general readability refactor, no impact made)
f7d9b9c to
f8b0984
Compare
yair100
left a comment
There was a problem hiding this comment.
I can confirm these changes are working as expected.
0x5bfa
left a comment
There was a problem hiding this comment.
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;
}
Resolved / Related Issues
Steps used to test these changes
tar --exclude=archive.tar -cf archive.tar .in Powershell