Skip to content

Commit

Permalink
fix OverflowError when System.DateTime has DateTimeKind bits set
Browse files Browse the repository at this point in the history
  • Loading branch information
nightlark authored and malwarefrank committed Oct 19, 2024
1 parent fcccdaf commit 1c4007b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/dnfile/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,18 @@ def type_str_to_type(self, type_name: str, data: bytes, offset: int) -> Tuple[Op
tsize = 8
final_bytes = data[offset:offset + tsize]
x = struct.unpack("<q", final_bytes)[0]
# Value is stored in lower 62-bits
# https://github.com/dotnet/runtime/blob/17c55f1/src/libraries/System.Private.CoreLib/src/System/DateTime.cs#L130-L138
x = x & ((1 << 62) - 1)
# https://stackoverflow.com/questions/3169517/python-c-sharp-binary-datetime-encoding
secs = x / 10.0 ** 7
delta = datetime.timedelta(seconds=secs)
dt = datetime.datetime(1, 1, 1) + delta
final_value = dt
try:
dt = datetime.datetime(1, 1, 1) + delta
final_value = dt
except OverflowError:
# TODO warn/error
pass
elif type_name == "System.TimeSpan":
# TODO return resourceDataFactory.Create(new TimeSpan(reader.ReadInt64()));
tsize = 8
Expand Down

0 comments on commit 1c4007b

Please sign in to comment.