Skip to content

Commit

Permalink
Fix a crash when all 64 bits in timestamp are 1 (#22)
Browse files Browse the repository at this point in the history
We've found some .msg files in the wild that have a CREATION_TIME that
has all 64 bits set: 9223372036854775807.

Adding this number of 100ns intervals to the base timestamp of
1601-01-01 results in a timestamp somewhere in the year 30828 which is
not supported by Python's datetime module, as datetime.MAXYEAR is
currently 9999.

Co-authored-by: Martijn van de Streek <[email protected]>
  • Loading branch information
Martijn van de Streek and Martijn van de Streek authored Feb 10, 2022
1 parent 64c07db commit 5fa8976
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion outlookmsgfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,11 @@ def load(value):
# 100-nanosecond intervals since January 1, 1601.
from datetime import datetime, timedelta
value = reduce(lambda a, b : (a<<8)+b, reversed(value)) # bytestring to integer
value = datetime(1601, 1, 1) + timedelta(seconds=value/10000000)
try:
value = datetime(1601, 1, 1) + timedelta(seconds=value/10000000)
except OverflowError:
value = None

return value

# TODO: The other fixed-length data types:
Expand Down

0 comments on commit 5fa8976

Please sign in to comment.