Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ts: Make dostimestamp() fall back to epoch on parse failures #37

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
ts: Make dostimestamp() fall back to epoch on parse failures
If we detect corrupt timestamp data, fall back to the DOS epoch instead
of passing on the ValueError from datetime(), which would stop parsing
all together.
  • Loading branch information
syzzer committed Dec 13, 2023
commit 737386424f3f4dda35ce16262a8b1c50ed2e1630
7 changes: 6 additions & 1 deletion dissect/util/ts.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,12 @@ def dostimestamp(ts: int, centiseconds: int = 0, swap: bool = False) -> datetime
# extra_seconds will be at most 1.
extra_seconds, centiseconds = divmod(centiseconds, 100)
microseconds = centiseconds * 10000
timestamp = datetime(year, month, day, hours, minutes, seconds + extra_seconds, microseconds)

try:
timestamp = datetime(year, month, day, hours, minutes, seconds + extra_seconds, microseconds)
except ValueError:
# If we fail to parse, fall back to the DOS epoch
timestamp = datetime(DOS_EPOCH_YEAR, 1, 1)

return timestamp

Expand Down