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

Fix OverflowError when System.DateTime has DateTimeKind bits set #88

Merged
merged 1 commit into from
Oct 19, 2024
Merged
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
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
Loading