Skip to content

Commit b3e01e7

Browse files
committed
Disable analysis log truncation if buffer is configured to 0
1 parent 2283cfb commit b3e01e7

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/cuckoo/common/utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,18 @@ def convert_to_printable_and_truncate(s: str, buf: int, cache=None):
342342
return convert_to_printable(f"{s[:buf]} <truncated>" if len(s) > buf else s, cache=cache)
343343

344344

345+
def truncate_str(s: str, max_length: int, marker=" <truncated>"):
346+
"""Truncate a string if its length exceeds the configured `max_length`.
347+
348+
If `max_length` is less than or equal to 0, the string is not modified.
349+
If the string is truncated, `marker` is added to the end."""
350+
truncate_size = min(max_length, len(s))
351+
if truncate_size > 0 and truncate_size < len(s):
352+
return f"{s[:truncate_size]}{marker}"
353+
else:
354+
return s
355+
356+
345357
def convert_filename_char(c):
346358
"""Escapes filename characters.
347359
@param c: dirty char.

modules/processing/debug.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from lib.cuckoo.common.abstracts import Processing
88
from lib.cuckoo.common.exceptions import CuckooProcessingError
99
from lib.cuckoo.common.path_utils import path_exists
10+
from lib.cuckoo.common.utils import truncate_str
1011
from lib.cuckoo.core.database import Database
1112

1213

@@ -24,7 +25,7 @@ def run(self):
2425
try:
2526
buf_size = self.options.get("buffer", 8192)
2627
content = codecs.open(self.log_path, "rb", "utf-8").read()
27-
debug["log"] = content[:buf_size] + " <truncated>" if len(content) > buf_size else content
28+
debug["log"] = truncate_str(content, buf_size)
2829
except ValueError as e:
2930
raise CuckooProcessingError(f"Error decoding {self.log_path}: {e}") from e
3031
except (IOError, OSError) as e:

0 commit comments

Comments
 (0)