Fix OverflowError when System.DateTime has DateTimeKind bits set #88
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've had several users encounter dotnet assemblies (mostly resource dlls) that cause dnfile to throw an
OverflowError: date value out of range
exception (stack trace below). Looking into the dotnet System.DateTime data type, the ticks value is actually just stored using the lower 62-bits. The upper 2 bits are a DateTimeKind that is either unspecified, UTC, or Local.Zeroing out the upper 2 bits resolves these cases for dotnet binaries with a "valid" System.DateTime (defined as up to 12/31/9999 23:59:59.9999999 according to a comment in the dotnet source code). However there is still a possibility that a malformed binary could encode a 62-bit value that still results in an OverflowError in Python's date time module, so that exception should be caught and handled slightly gracefully so parsing the rest of the file can at least continue.
I was trying to decide if anything special needs to be done to handle the DateTimeKind, but there isn't enough information to know what the local timezone was when the file got created for converting between time zones.
Unfortunately, the sample files I have aren't ones that I'm able to share.
Comment in the dotnet runtime sourcecode about the format for System.DateTime: https://github.com/dotnet/runtime/blob/17c55f1/src/libraries/System.Private.CoreLib/src/System/DateTime.cs#L130-L138