Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: overwrite symlinks when extracting tarballs #867

Merged
merged 28 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions content/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,8 @@
return s.graph.Predecessors(ctx, node)
}

// Add adds a file into the file store.
// Add adds a file or a directory into the file store.
// Hard links within the directory are treated as regular files.
func (s *Store) Add(ctx context.Context, name, mediaType, path string) (ocispec.Descriptor, error) {
if s.isClosedSet() {
return ocispec.Descriptor{}, ErrStoreClosed
Expand Down Expand Up @@ -615,16 +616,16 @@
}
rel, err := filepath.Rel(base, target)
if err != nil {
return "", ErrPathTraversalDisallowed
return "", fmt.Errorf("target path '%s' is outside of working dir '%s': %w", path, base, ErrPathTraversalDisallowed)

Check warning on line 619 in content/file/file.go

View check run for this annotation

Codecov / codecov/patch

content/file/file.go#L619

Added line #L619 was not covered by tests
}
rel = filepath.ToSlash(rel)
if strings.HasPrefix(rel, "../") || rel == ".." {
return "", ErrPathTraversalDisallowed
return "", fmt.Errorf("target path '%s' is outside of working dir '%s' : %w", path, base, ErrPathTraversalDisallowed)
}
}
if s.DisableOverwrite {
if _, err := os.Stat(path); err == nil {
return "", ErrOverwriteDisallowed
return "", fmt.Errorf("file %s already exists: %w", path, ErrOverwriteDisallowed)
} else if !os.IsNotExist(err) {
return "", err
}
Expand Down
Loading
Loading