Entry is trying to write a file outside of the destination #677

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

Originally created by @crystalgreen on GitHub (Mar 21, 2025).

Originally assigned to: @Copilot on GitHub.

I get the above mentioned error with this code

        using var reader = package.ExtractAllEntries();
        reader.WriteAllToDirectory(pkgWorkDir, new SharpCompress.Common.ExtractionOptions { PreserveFileTime = true, ExtractFullPath = true, Overwrite = true, PreserveAttributes = true });

when running as Windows Service and the LocalSystem account. I use pkgWorkDir that is constructed starting with Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData).

On my system, this returns C:\Windows\system32\config\systemprofile\AppData\Local.
The code throws the error

Entry is trying to write a file outside of the destination directory: C:\Windows\system32\config\systemprofile\AppData\Local

As one can see, there is a difference between System32 and system32.

The lib code here uses StringComparison.Ordinal to compare the strings.

My issue could be fixed, if - under Windows OS - we use StringComparison.OrdinalIgnoreCase.

Originally created by @crystalgreen on GitHub (Mar 21, 2025). Originally assigned to: @Copilot on GitHub. I get the above mentioned error with this code ```csharp using var reader = package.ExtractAllEntries(); reader.WriteAllToDirectory(pkgWorkDir, new SharpCompress.Common.ExtractionOptions { PreserveFileTime = true, ExtractFullPath = true, Overwrite = true, PreserveAttributes = true }); ``` when running as Windows Service and the LocalSystem account. I use _pkgWorkDir_ that is constructed starting with `Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)`. On my system, this returns `C:\Windows\system32\config\systemprofile\AppData\Local`. The code throws the error > Entry is trying to write a file outside of the destination directory: C:\Windows\system32\config\systemprofile\AppData\Local As one can see, there is a difference between _System32_ and _system32_. The lib code [here](https://github.com/adamhathcock/sharpcompress/blob/227f66f29962a2d8632a71d7c4cdf3d8631c8530/src/SharpCompress/Common/ExtractionMethods.cs#L72) uses `StringComparison.Ordinal` to compare the strings. My issue could be fixed, if - under Windows OS - we use `StringComparison.OrdinalIgnoreCase`.
claunia added the bugup for grabs labels 2026-01-29 22:15: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#677