Skip to content

Find, verify, and analyze leaked credentials

refactor(handlers): move timeout to archive file (#3918)

Richard Gomezb332fea5dc7b
diff --git a/pkg/handlers/archive.go b/pkg/handlers/archive.go
index 48595096c..042629396 100644
--- a/pkg/handlers/archive.go
+++ b/pkg/handlers/archive.go
@@ -23,8 +23,9 @@ const (
var (
// NOTE: This is a temporary workaround for |openArchive| incrementing depth twice per archive.
// See: https://github.com/trufflesecurity/trufflehog/issues/2942
- maxDepth = 5 * 2
- maxSize = 2 << 30 // 2 GB
+ maxDepth = 5 * 2
+ maxSize = 2 << 30 // 2 GB
+ maxTimeout = time.Duration(60) * time.Second
)
// SetArchiveMaxSize sets the maximum size of the archive.
@@ -33,6 +34,9 @@ func SetArchiveMaxSize(size int) { maxSize = size }
// SetArchiveMaxDepth sets the maximum depth of the archive.
func SetArchiveMaxDepth(depth int) { maxDepth = depth }
+// SetArchiveMaxTimeout sets the maximum timeout for the archive handler.
+func SetArchiveMaxTimeout(timeout time.Duration) { maxTimeout = timeout }
+
// archiveHandler is a handler for common archive files that are supported by the archiver library.
type archiveHandler struct{ *defaultHandler }
diff --git a/pkg/handlers/handlers.go b/pkg/handlers/handlers.go
index f7a2681f1..0a5b0e744 100644
--- a/pkg/handlers/handlers.go
+++ b/pkg/handlers/handlers.go
@@ -8,7 +8,6 @@ import (
"fmt"
"io"
"path/filepath"
- "time"
"github.com/gabriel-vasile/mimetype"
"github.com/mholt/archives"
@@ -322,11 +321,6 @@ func selectHandler(mimeT mimeType, isGenericArchive bool) FileHandler {
}
}
-var maxTimeout = time.Duration(60) * time.Second
-
-// SetArchiveMaxTimeout sets the maximum timeout for the archive handler.
-func SetArchiveMaxTimeout(timeout time.Duration) { maxTimeout = timeout }
-
// HandleFile orchestrates the complete file handling process for a given file.
// It determines the MIME type of the file,
// selects the appropriate handler based on this type, and processes the file.