Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
[bug] - Recover From Panic During Archive Handling (#3348)
ahrav350db3a11e00
diff --git a/pkg/handlers/archive.go b/pkg/handlers/archive.goindex ed663c258..d33329f76 100644--- a/pkg/handlers/archive.go+++ b/pkg/handlers/archive.go@@ -53,11 +53,26 @@ func (h *archiveHandler) HandleFile(ctx logContext.Context, input fileReader) (c}go func() {+ var err errordefer close(dataChan)+ // The underlying 7zip library may panic when attempting to open an archive.+ // This is due to an Index Out Of Range (IOOR) error when reading the archive header.+ // See: https://github.com/bodgit/sevenzip/blob/74bff0da9b233317e4ea7dd8c184a315db71af2a/types.go#L846+ defer func() {+ if r := recover(); r != nil {+ // Return the panic as an error.+ if e, ok := r.(error); ok {+ err = e+ } else {+ err = fmt.Errorf("panic occurred: %v", r)+ }+ ctx.Logger().Error(err, "Panic occurred when attempting to open archive")+ }+ }()+// Update the metrics for the file processing.start := time.Now()- var err errordefer func() {h.measureLatencyAndHandleErrors(start, err)h.metrics.incFilesProcessed()