Skip to content

Commit

Permalink
Address review comments from Billy and tested code
Browse files Browse the repository at this point in the history
  • Loading branch information
suganyas committed Jun 27, 2023
1 parent f35ce50 commit 791f162
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
12 changes: 4 additions & 8 deletions cmd/oras/internal/option/packer.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/spf13/pflag"
"oras.land/oras-go/v2/content"
"oras.land/oras/cmd/oras/internal/fileref"
)

// Pre-defined annotation keys for annotation file
Expand Down Expand Up @@ -80,17 +81,12 @@ func (opts *Packer) Parse() error {
if !opts.PathValidationDisabled && len(opts.FileRefs) != 0 {
for _, path := range opts.FileRefs {
//Remove the type if specified in the path <file>[:<type>] format
lastIndex := strings.LastIndex(path, ":")
if lastIndex != -1 {
path = path[:lastIndex]
}
absPath, err := filepath.Abs(path)
dirPath := filepath.Dir(absPath)
path, _, err = fileref.Parse(path, "")
if err != nil {
return err
}
if dirPath != currentDir {
failedPaths = append(failedPaths, absPath)
if filepath.IsAbs(path) {
failedPaths = append(failedPaths, path)
}
}
if len(failedPaths) > 0 {
Expand Down
6 changes: 2 additions & 4 deletions cmd/oras/root/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"errors"
"fmt"
"io"
"strings"
"sync"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
Expand Down Expand Up @@ -239,9 +238,8 @@ func runPull(ctx context.Context, opts pullOptions) error {
// Copy
desc, err := oras.Copy(ctx, src, opts.Reference, dst, opts.Reference, copyOptions)
if err != nil {
if strings.Contains(err.Error(), "path traversal disallowed") {
errorMsg := fmt.Sprintf("%v: %w ", "to enable path traversal use --allow-path-traversal flag", err)
return errors.New(errorMsg)
if errors.Is(err, file.ErrPathTraversalDisallowed) {
err = fmt.Errorf("%s: %w", "use option -T/allow-path-traversal to allow pulling outside of working directory", err)
}
return err
}
Expand Down

0 comments on commit 791f162

Please sign in to comment.