Skip to content

improve handling of local vs POSIX paths - #37

Draft
thaJeztah wants to merge 4 commits into
moby:mainfrom
thaJeztah:more_posix
Draft

improve handling of local vs POSIX paths#37
thaJeztah wants to merge 4 commits into
moby:mainfrom
thaJeztah:more_posix

Conversation

@thaJeztah

@thaJeztah thaJeztah commented Jul 15, 2026

Copy link
Copy Markdown
Member

ExportChanges: use POSIX / Unix conventions for Tar operations

The Change.Path field holds a local path, but it was used to set
the Tar.Name field.

Convert the path to a POSIX / Unix path before setting. Also explicitly
convert the archive-path to a POSIX path when calling addTarFile, and
explicitly strip a leading / (if present), instead of the first
character.

createImpliedDirectories: fix directory detection and path handling

The code used os.PathSeparator to detect if the Tar-header was not for
a directory, but Tar headers use POSIX (forward-slashes), so this would
fail on Windows.

While updating, also update the parent path handling to use the right
conventions (forward-slashes) before constructing a local path.

RebaseArchiveEntries: use POSIX / Unix paths

This is mostly defense-in-depth; RebaseArchiveEntries is manipulating
the Tar headers, which use POSIX / Unix paths; convert the given paths
on the way in.

@codecov-commenter

codecov-commenter commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.77778% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.27%. Comparing base (2cd730e) to head (07624f9).
⚠️ Report is 175 commits behind head on main.

Files with missing lines Patch % Lines
diff.go 50.00% 2 Missing and 1 partial ⚠️
archive.go 91.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #37      +/-   ##
==========================================
- Coverage   66.35%   65.27%   -1.08%     
==========================================
  Files          42       42              
  Lines        2027     2036       +9     
==========================================
- Hits         1345     1329      -16     
- Misses        497      533      +36     
+ Partials      185      174      -11     

☔ 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.

Comment thread diff.go Fixed
@thaJeztah

Copy link
Copy Markdown
Member Author

path too long?

=== RUN   TestPrefixHeaderReadable
    archive_test.go:1072: assertion failed: error is not nil: open C:\Users\RUNNER~1\AppData\Local\Temp\TestPrefixHeaderReadable1603880377\001\aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\foo: The system cannot find the path specified.
--- FAIL: TestPrefixHeaderReadable (0.01s)

Comment thread archive.go

// #nosec G305 -- The joined path is checked for path traversal.
dstPath := filepath.Join(dest, hdr.Name)
dstPath := filepath.Join(dest, filepath.FromSlash(hdr.Name))
Comment thread diff.go
// such hardlinks can be resolved.
if strings.HasPrefix(hdr.Name, WhiteoutLinkDir) && hdr.Typeflag == tar.TypeReg {
basename := filepath.Base(hdr.Name)
basename := path.Base(hdr.Name)
Comment thread archive.go
// This keeps "..\" as-is, but normalizes "\..\" to "\".
hdr.Name = filepath.Clean(hdr.Name)
// This keeps "../" as-is, but normalizes "/../" to "/".
hdr.Name = path.Clean(hdr.Name)
Comment thread diff.go

// Normalize name, for safety and for a simple is-root check
hdr.Name = filepath.Clean(hdr.Name)
hdr.Name = path.Clean(hdr.Name)
Comment thread diff.go
// #nosec G305 -- The joined path is guarded against path traversal.
path := filepath.Join(dest, hdr.Name)
rel, err := filepath.Rel(dest, path)
dstPath := filepath.Join(dest, filepath.FromSlash(hdr.Name))
@thaJeztah
thaJeztah marked this pull request as draft July 15, 2026 12:23
@thaJeztah
thaJeztah force-pushed the more_posix branch 4 times, most recently from 3d3db1b to 385e837 Compare July 15, 2026 14:54
The code used os.PathSeparator to detect if the Tar-header was not for
a directory, but Tar headers use POSIX (forward-slashes), so this would
fail on Windows.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Update the parent path handling to use the right conventions (forward-slashes)
before constructing a local path.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
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