File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed
Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change 66from structlog import get_logger
77
88from unblob .models import DirectoryExtractor , ExtractError , Extractor
9- from unblob .report import ExtractCommandFailedReport , ExtractorDependencyNotFoundReport
9+ from unblob .report import (
10+ ExtractCommandFailedReport ,
11+ ExtractorDependencyNotFoundReport ,
12+ ExtractorTimedOut ,
13+ )
1014
1115if TYPE_CHECKING :
1216 import io
1317
18+ # value that is high enough not to block long running execution such as extraction of large
19+ # disk images, but small enough to make sure unblob finish its execution at some point.
20+ COMMAND_TIMEOUT = 12 * 60 * 60
21+
1422logger = get_logger ()
1523
1624
@@ -45,6 +53,7 @@ def no_op():
4553 cmd ,
4654 stdout = stdout_file ,
4755 stderr = subprocess .PIPE ,
56+ timeout = COMMAND_TIMEOUT ,
4857 )
4958 if res .returncode != 0 :
5059 error_report = ExtractCommandFailedReport (
@@ -65,6 +74,13 @@ def no_op():
6574 ** error_report .asdict (),
6675 )
6776 raise ExtractError (error_report ) from None
77+ except subprocess .TimeoutExpired as e :
78+ error_report = ExtractorTimedOut (cmd = e .cmd , timeout = e .timeout )
79+ logger .error (
80+ "Extract command timed out." ,
81+ ** error_report .asdict (),
82+ )
83+ raise ExtractError (error_report ) from None
6884 finally :
6985 cleanup ()
7086
Original file line number Diff line number Diff line change @@ -103,6 +103,15 @@ class ExtractorDependencyNotFoundReport(ErrorReport):
103103 dependencies : List [str ]
104104
105105
106+ @attr .define (kw_only = True , frozen = True )
107+ class ExtractorTimedOut (ErrorReport ):
108+ """Describes an error when the extractor execution timed out."""
109+
110+ severity : Severity = Severity .ERROR
111+ cmd : str
112+ timeout : float
113+
114+
106115@attr .define (kw_only = True , frozen = True )
107116class MaliciousSymlinkRemoved (ErrorReport ):
108117 """Describes an error when malicious symlinks have been removed from disk."""
You can’t perform that action at this time.
0 commit comments