Skip to content

chrootarchive: use archive untar implementation on Windows - #107

Open
thaJeztah wants to merge 1 commit into
moby:mainfrom
thaJeztah:chrootarchive_windows
Open

chrootarchive: use archive untar implementation on Windows#107
thaJeztah wants to merge 1 commit into
moby:mainfrom
thaJeztah:chrootarchive_windows

Conversation

@thaJeztah

Copy link
Copy Markdown
Member

Windows does not support chroot-based extraction, so there is no need to duplicate archive's decompression and untar handling.

Move the existing chroot-based handler to the Unix implementation. On Windows, retain the existing destination setup, then delegate directly to archive.Untar or archive.UntarUncompressed.

This keeps the Unix behavior unchanged while removing the redundant Windows invokeUnpack path.

@codecov-commenter

codecov-commenter commented Aug 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.41935% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.26%. Comparing base (e738eed) to head (54dddcd).
⚠️ Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
chrootarchive/archive_windows.go 58.33% 4 Missing and 1 partial ⚠️
chrootarchive/archive_unix.go 89.47% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #107      +/-   ##
==========================================
+ Coverage   65.25%   65.26%   +0.01%     
==========================================
  Files          46       46              
  Lines        2377     2398      +21     
==========================================
+ Hits         1551     1565      +14     
- Misses        606      610       +4     
- Partials      220      223       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The Windows extraction path currently does not enforce the UntarWithRoot containment contract (root vs dest), which is a security-relevant behavior gap in the modified code path.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Pull request overview

Refactors chrootarchive extraction so Windows no longer duplicates decompression/untar logic and instead delegates directly to archive.Untar / archive.UntarUncompressed, while keeping the chroot-based path on non-Windows platforms.

Changes:

  • Moved the shared untarHandler implementation into the non-Windows (!windows) implementation.
  • Replaced the Windows invokeUnpack path with direct calls to archive.Untar / archive.UntarUncompressed.
  • Adjusted imports and platform-specific destination setup to match the new split.
File summaries
File Description
chrootarchive/archive.go Removes the shared untarHandler from the common file and relies on platform-specific implementations.
chrootarchive/archive_windows.go Implements Windows untarHandler by preparing destination and delegating to archive.Untar*.
chrootarchive/archive_unix.go Adds the chroot-based untarHandler implementation for non-Windows builds.
Review details

Suppressed comments (2)

chrootarchive/archive_windows.go:39

  • This comment refers to "entering the chroot", but Windows explicitly does not support chroot; the wording is misleading for this platform-specific implementation.
	// Create dest here only if it is the root itself; paths below the root are
	// created by the extractor after entering the chroot.
	// This case is only currently used by cp.

chrootarchive/archive_windows.go:43

  • Passing mode 0 to os.MkdirAll is unusual and makes intent unclear; use a conventional directory mode (it is ignored on Windows but keeps behavior clear and consistent).
			if err := os.MkdirAll(dest, 0); err != nil {
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Comment on lines +32 to +36
func untarHandler(tarArchive io.Reader, dest string, options *archive.TarOptions, decompress bool, root string) error {
if tarArchive == nil {
return errors.New("empty archive")
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yup, pre-existing issue, and one of the reasons I opened this PR. Peeling away a level of abstraction to make it clear that we're not actually using chrootarchive here.

Possibly on Windows we can do a os.Root based equivalent.

@thaJeztah thaJeztah self-assigned this Aug 5, 2026
Windows does not support chroot-based extraction, so there is no need
to duplicate archive's decompression and untar handling.

Move the existing chroot-based handler to the Unix implementation. On
Windows, retain the existing destination setup, then delegate directly
to archive.Untar or archive.UntarUncompressed.

This keeps the Unix behavior unchanged while removing the redundant
Windows invokeUnpack path.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah
thaJeztah force-pushed the chrootarchive_windows branch from e8c3b2d to 54dddcd Compare August 14, 2026 14:15
@thaJeztah
thaJeztah marked this pull request as ready for review August 14, 2026 14:23
@thaJeztah
thaJeztah requested review from crazy-max and vvoland August 14, 2026 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants