mirror of
https://github.com/trufflesecurity/trufflehog.git
synced 2024-11-10 07:04:24 +00:00
Return an error from ReadToMax when it panics (#925)
This commit is contained in:
parent
eb4ff435a5
commit
b3d3f531a4
1 changed files with 9 additions and 3 deletions
|
@ -136,14 +136,20 @@ func (d *Archive) extractorHandler(archiveChan chan ([]byte)) func(context.Conte
|
|||
}
|
||||
|
||||
// ReadToMax reads up to the max size.
|
||||
func (d *Archive) ReadToMax(reader io.Reader) ([]byte, error) {
|
||||
func (d *Archive) ReadToMax(reader io.Reader) (data []byte, err error) {
|
||||
// Archiver v4 is in alpha and using an experimental version of
|
||||
// rardecode. There is a bug somewhere with rar decoder format 29
|
||||
// that can lead to a panic. An issue is open in rardecode repo
|
||||
// https://github.com/nwaples/rardecode/issues/30.
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
log.Errorf("Panic occurred when reading archive: %v", err)
|
||||
if r := recover(); r != nil {
|
||||
log.Errorf("Panic occurred when reading archive: %v", r)
|
||||
// Return an error from ReadToMax.
|
||||
if e, ok := r.(error); ok {
|
||||
err = e
|
||||
} else {
|
||||
err = fmt.Errorf("Panic occurred: %v", r)
|
||||
}
|
||||
}
|
||||
}()
|
||||
fileContent := bytes.Buffer{}
|
||||
|
|
Loading…
Reference in a new issue