fix(sevenzip): add nil guard for subreader to prevent panic
When opening a sevenzip archive, the init() method calls sr :=SevenZipReader() but never checked if sr was nil before using it. This could cause a nil pointer dereference when processing malformed or empty archives. Add an explicit nil check returning errFormat early if the subreader is nil. Also fixes a minor import grouping whitespace issue.
This commit is contained in:
@@ -19,6 +19,7 @@ import (
|
||||
|
||||
"bookhoard/internal/sevenzip/internal/pool"
|
||||
"bookhoard/internal/sevenzip/internal/util"
|
||||
|
||||
"github.com/bodgit/plumbing"
|
||||
"github.com/spf13/afero"
|
||||
)
|
||||
@@ -415,6 +416,10 @@ func (z *Reader) init(r io.ReaderAt, size int64) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
if sr == nil {
|
||||
return errFormat
|
||||
}
|
||||
|
||||
// Work out where we are in the file (32, avoiding magic numbers)
|
||||
if z.start, err = sr.Seek(0, io.SeekCurrent); err != nil {
|
||||
return fmt.Errorf("sevenzip: error seeking current position: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user