Skip to content

Commit

Permalink
fix OverflowError when parsing System.DateTime with DateTimeKind bits…
Browse files Browse the repository at this point in the history
… set
  • Loading branch information
nightlark committed Oct 7, 2024
1 parent fcccdaf commit fac90ac
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/dnfile/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ 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)
Expand Down

0 comments on commit fac90ac

Please sign in to comment.