Skip to content

Commit

Permalink
handle invalid tarball
Browse files Browse the repository at this point in the history
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
  • Loading branch information
qweeah committed Nov 7, 2023
1 parent 91a4897 commit 6867eff
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions cmd/oras/internal/option/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"context"
"errors"
"fmt"
"io"
"io/fs"
"os"
"strings"
"sync"
Expand Down Expand Up @@ -148,18 +150,27 @@ func (opts *Target) NewReadonlyTarget(ctx context.Context, common Common, logger
switch opts.Type {
case TargetTypeOCILayout:
var err error

opts.Path, opts.Reference, err = parseOCILayoutReference(opts.RawReference)
if err != nil {
return nil, err
}
info, err := os.Stat(opts.Path)
if err != nil {
return nil, fmt.Errorf("invalid path in %q: %w", opts.RawReference, err)
if errors.Is(err, fs.ErrNotExist) {
err = fmt.Errorf("invalid path in %q: %w", opts.RawReference, err)
}
return nil, err
}
if info.IsDir() {
return oci.NewFromFS(ctx, os.DirFS(opts.Path))
}
return oci.NewFromTar(ctx, opts.Path)
store, err := oci.NewFromTar(ctx, opts.Path)
if err != nil && errors.Is(err, io.ErrUnexpectedEOF) {
err = fmt.Errorf("%q is not a valid tarball archive file: %w", opts.Path, err)
}
return store, err

case TargetTypeRemote:
repo, err := opts.NewRepository(opts.RawReference, common, logger)
if err != nil {
Expand Down

0 comments on commit 6867eff

Please sign in to comment.