Skip to content

Commit

Permalink
fix: add missing error check in archive handler (#1770)
Browse files Browse the repository at this point in the history
Fixes #1769

The existing error check `errors.Is(err, archiver.ErrNoMatch) && depth >
0` only conditionally handled a specific error.

Any other error case was not short circuited and ended up causing a
nil-pointer dereference further down the method when `format.Name()` was
invoked.
  • Loading branch information
martinohmann authored Sep 13, 2023
1 parent 72b6a9e commit 31d17c4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/handlers/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ func (a *Archive) openArchive(ctx context.Context, depth int, reader io.Reader,
return a.handleNonArchiveContent(ctx, arReader, archiveChan)
}

if err != nil {
return err
}

switch archive := format.(type) {
case archiver.Decompressor:
info := decompressorInfo{depth: depth, reader: arReader, archiveChan: archiveChan, archiver: archive}
Expand Down
12 changes: 12 additions & 0 deletions pkg/handlers/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,15 @@ func TestExtractRPMContent(t *testing.T) {
expectedLength := 1822720
assert.Equal(t, expectedLength, len(string(content)))
}

func TestOpenInvalidArchive(t *testing.T) {
reader := strings.NewReader("invalid archive")

ctx := logContext.AddLogger(context.Background())
a := &Archive{}

archiveChan := make(chan []byte)

err := a.openArchive(ctx, 0, reader, archiveChan)
assert.Error(t, err)
}

0 comments on commit 31d17c4

Please sign in to comment.