Skip to content

Commit

Permalink
Merge pull request mandiant#846 from Arker123/empty-file
Browse files Browse the repository at this point in the history
Handle Empty File Exception in FLOSS Execution
  • Loading branch information
williballenthin committed Aug 1, 2023
2 parents 7cd6737 + dd8b890 commit 79809d2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions floss/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,11 @@ def main(argv=None) -> int:
# can throw away result later if not desired in output
time0 = time()
interim = time0

static_strings = get_static_strings(sample, args.min_length)
if static_strings == []:
return 0

static_runtime = get_runtime_diff(interim)

lang_id = identify_language(sample, static_strings)
Expand Down
5 changes: 5 additions & 0 deletions floss/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,11 @@ def get_static_strings(sample: Path, min_length: int) -> list:
"""
Returns list of static strings from the file which are above the minimum length
"""

if sample.stat().st_size == 0:
logger.warning("File is empty")
return []

with sample.open("r") as f:
if hasattr(mmap, "MAP_PRIVATE"):
# unix
Expand Down

0 comments on commit 79809d2

Please sign in to comment.