Repository navigation
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #127 +/- ##
==========================================
+ Coverage 65.48% 74.98% +9.50%
==========================================
Files 46 48 +2
Lines 2393 2439 +46
==========================================
+ Hits 1567 1829 +262
- Misses 605 607 +2
+ Partials 221 3 -218 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟡 Changes recommended
Empty destinations can unexpectedly target the working directory, and Unix xattr handling has a special-file race.
2 open findings
What changed in this PR
Adds caller-owned os.Root support for extraction while preserving directory identity across renames.
Changes:
- Adds
TarOptions.DestinationRootand root-relative extraction. - Adds platform-specific xattr handling and unsupported-API validation.
- Adds contract, identity, and platform regression tests.
| File | Description |
|---|---|
archive.go |
Implements caller-owned extraction roots. |
rootpath.go |
Resolves paths through root handles. |
diff.go |
Rejects roots for layer extraction. |
chrootarchive/archive.go |
Rejects roots for chroot extraction. |
chrootarchive/diff.go |
Rejects roots for chroot layers. |
xattr_root_linux.go |
Adds root-safe Linux xattrs. |
xattr_root_unix.go |
Adds descriptor-based Unix xattrs. |
xattr_unsupported.go |
Adds unsupported-platform stub. |
destination_root_test.go |
Tests API contracts and containment. |
destination_root_darwin_test.go |
Tests macOS node restrictions. |
archive_test.go |
Tests root identity preservation. |
archive_unix_test.go |
Updates root-path tests. |
xattr_root_linux_test.go |
Tests Linux xattr identity. |
xattr_root_unix_test.go |
Tests Unix xattr behavior. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
vvoland
force-pushed
the
extraction-root2
branch
3 times, most recently
from
October 13, 2026 14:29
1d0015e to
0fd79b2
Compare
Extraction opens its destination as an os.Root, but resolved parents of missing or escaping paths through root.Name(). If the destination was renamed and replaced during extraction, that fallback resolved symlinks in the replacement directory. resolveRootPath now walks symlinks through the os.Root handle and returns root-relative paths. The opaque whiteout walk now uses fs.WalkDir over root.FS(), so it no longer needs a host path. xattrs and darwin mknod have no portable handle-relative API, so they still use a host path from fsRootPath. fsRootPath now takes the caller's *os.Root, resolves through it, and returns a breakout error if the host path's parent is not the same file as the parent resolved through the handle. The remaining window between that check and the host-path operation is the same one that existed before. Signed-off-by: Paweł Gronowski <git@grono.dev>
Add DestinationRoot to TarOptions so callers can extract relative to an already-open os.Root. This preserves a caller-vetted directory identity when its pathname is renamed or replaced before extraction begins. Keep the existing behavior when DestinationRoot is unset. Treat dest as root-relative when it is set, retain caller ownership of the supplied root, and close only roots derived for nested destinations. Add coverage that replaces the original destination path after its root is opened and verifies that extraction still writes to the opened directory and does not close the caller-owned root. Signed-off-by: Remy Suen <remy.suen@docker.com> Assited-by: ChatGPT <noreply@openai.com>
macOS created device nodes and FIFOs through a pathname derived from root.Name(). When a caller supplied a renamed DestinationRoot, that path could identify a replacement directory instead. Reject these entries with ENOTSUP when DestinationRoot is set because macOS has no mknodat operation to preserve directory identity. Signed-off-by: Paweł Gronowski <git@grono.dev>
Extraction with a caller-owned root could apply metadata to a replacement directory after the selected directory was renamed. Applied extended attributes without using the root's original pathname. Kept dest relative to DestinationRoot, retained caller ownership, and closed only roots opened for nested destinations. An empty dest or "." extracts directly into the supplied root. Outside Linux, extended attributes are set through a descriptor. Reject them with ENOTSUP on symlinks, devices, and FIFOs, since opening a device node can trigger driver side effects, and granted owner read access only while opening entries the owner cannot read. On Linux, they are set through /proc/self/fd, which must be mounted. Signed-off-by: Paweł Gronowski <git@grono.dev>
vvoland
force-pushed
the
extraction-root2
branch
2 times, most recently
from
October 13, 2026 14:36
0fd79b2 to
990e5c1
Compare
Layer extraction silently ignored DestinationRoot. Chroot extraction could not preserve the supplied root consistently across platforms. Callers could therefore mistake the option for an enforced directory boundary. Reject DestinationRoot in those extraction entry points instead of ignoring it or passing it into chroot machinery. Existing callers without DestinationRoot remain unaffected. Signed-off-by: Paweł Gronowski <git@grono.dev>
vvoland
force-pushed
the
extraction-root2
branch
from
October 13, 2026 14:39
990e5c1 to
ebb6313
Compare
This was referenced Oct 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
Add
TarOptions.DestinationRootso callers can extract relative to an already-open*os.Root.Existing callers are unaffected. When
DestinationRootis nil, extraction continues to opendestdirectly as it does today.Motivation
For the general case, passing a root is equivalent to allowing
Unpackto callos.OpenRoot(dest)itself. The distinction matters when a caller already has a vetted directory handle.If the caller converts that handle back into a pathname, the pathname can be renamed or replaced before
Unpackopens it. Extraction may then operate on a different directory from the one the caller selected. Passing the existingos.Rootpreserves that directory identity.This keeps authorization with the application while allowing
go-archiveto perform extraction through the boundary the application established.