-
Notifications
You must be signed in to change notification settings - Fork 98
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: update error returned when oci.NewFromTar
is used with a non-tar file
#793
base: main
Are you sure you want to change the base?
Changes from all commits
995e97f
7fc9e05
b5c7ebd
275a44a
51ec1d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
non-empty file |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,7 @@ func New(path string) (*TarFS, error) { | |
if err != nil { | ||
return nil, fmt.Errorf("failed to resolve absolute path for %s: %w", path, err) | ||
} | ||
|
||
tarfs := &TarFS{ | ||
path: pathAbs, | ||
entries: make(map[string]*entry), | ||
|
@@ -135,8 +136,16 @@ func (tfs *TarFS) indexEntries() error { | |
header, err := tr.Next() | ||
if err != nil { | ||
if errors.Is(err, io.EOF) { | ||
if len(tfs.entries) == 0 { | ||
// indicates the given file is empty | ||
return fmt.Errorf("%s: file is empty: %w", tfs.path, errdef.ErrInvalidTarFile) | ||
} | ||
Comment on lines
+139
to
+142
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we should return error on empty valid tar files since it breaks the encapsulation principal. If we really want to check for empty tar file, it should be checked in the caller. |
||
break | ||
} | ||
if errors.Is(err, io.ErrUnexpectedEOF) { | ||
// indicates that its either not a tarfile or it is a corrupted one | ||
return fmt.Errorf("%s: %w", tfs.path, errdef.ErrInvalidTarFile) | ||
} | ||
Comment on lines
+145
to
+148
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
return err | ||
} | ||
pos, err := tarFile.Seek(0, io.SeekCurrent) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
non-empty file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just thinking out loud: From the
tarfs
point of view, the tar file can be empty. But sincetarfs
is an internal package and is only used byReadOnlyStorage
andReadOnlyOCI
, which requiresoci-layout
file in it, I think it makes sense to return an error for an empty tar file. 🤔