Skip to content

Cache normalized destination path during Zip extraction - #131792

Open
alinpahontu2912 with Copilot wants to merge 2 commits into
mainfrom
copilot/cache-normalized-destination-path
Open

Cache normalized destination path during Zip extraction#131792
alinpahontu2912 with Copilot wants to merge 2 commits into
mainfrom
copilot/cache-normalized-destination-path

Conversation

Copilot AI commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

ExtractRelativeToDirectoryCheckIfFile recomputed the destination root's Directory.CreateDirectory and Path.GetFullPath normalization on every entry, even though the root is constant for the entire ExtractToDirectory/ExtractToDirectoryAsync call.

Changes

  • Added ZipFileExtensions.GetDestinationDirectoryFullPath(string), computing the normalized root (create + trailing separator) once.
  • ExtractRelativeToDirectoryCheckIfFile, ExtractRelativeToDirectory, and ExtractRelativeToDirectoryAsync now take the pre-normalized root instead of the raw destination directory name.
  • Updated all extraction entry points (ZipFile.Extract(.Async).cs, ZipFileExtensions.ZipArchive.Extract(.Async).cs) to compute the root once before iterating entries, reusing it across the loop.
  • Path-traversal safety checks are untouched — only the redundant per-entry recomputation is removed.

Co-authored-by: alinpahontu2912 <56953855+alinpahontu2912@users.noreply.github.com>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

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 refactors ZIP extraction to compute and reuse a normalized destination directory root once per ExtractToDirectory / ExtractToDirectoryAsync invocation, rather than recomputing it for every entry extracted.

Changes:

  • Added ZipFileExtensions.GetDestinationDirectoryFullPath(string) to compute the destination root once (create + ensure trailing directory separator).
  • Updated per-entry extraction helpers to take the pre-normalized destination root instead of the raw destination directory name.
  • Updated all extraction entry points (sync/async, ZipArchive- and ZipFile-based) to compute the destination root once prior to iterating entries.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/libraries/System.IO.Compression.ZipFile/src/System/IO/Compression/ZipFileExtensions.ZipArchiveEntry.Extract.cs Introduces GetDestinationDirectoryFullPath and updates per-entry extraction helpers to use a cached normalized root.
src/libraries/System.IO.Compression.ZipFile/src/System/IO/Compression/ZipFileExtensions.ZipArchiveEntry.Extract.Async.cs Updates async entry extraction to use the pre-normalized destination root.
src/libraries/System.IO.Compression.ZipFile/src/System/IO/Compression/ZipFileExtensions.ZipArchive.Extract.cs Computes the destination root once per extraction and passes it through the entry loop.
src/libraries/System.IO.Compression.ZipFile/src/System/IO/Compression/ZipFileExtensions.ZipArchive.Extract.Async.cs Same as above for async ZipArchive extraction APIs.
src/libraries/System.IO.Compression.ZipFile/src/System/IO/Compression/ZipFile.Extract.cs Computes the destination root once per extraction and reuses it while extracting ZipFile entries.
src/libraries/System.IO.Compression.ZipFile/src/System/IO/Compression/ZipFile.Extract.Async.cs Same as above for async ZipFile extraction APIs.

ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(destinationDirectoryName);

string destinationDirectoryFullPath = GetDestinationDirectoryFullPath(destinationDirectoryName);
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @karelz, @dotnet/area-system-io-compression
See info in area-owners.md if you want to be subscribed.

@alinpahontu2912 alinpahontu2912 added this to the Future milestone Aug 4, 2026
@alinpahontu2912
alinpahontu2912 marked this pull request as ready for review August 4, 2026 11:08
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

… regression test

Co-authored-by: alinpahontu2912 <56953855+alinpahontu2912@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 4, 2026 11:51

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

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants