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

v1.0 ArgumentOutOfRangeException for DateTime before 1970 if has milliseconds. Works in 0.9.X #296

Closed
stbentia opened this issue Jul 9, 2018 · 2 comments · Fixed by #303
Labels
bug Detected as bug

Comments

@stbentia
Copy link

stbentia commented Jul 9, 2018

The code snippet below works with versions 0.9.0, 0.9.1, 0.9.2, but faults on 1.0.0 with this error:

System.ArgumentOutOfRangeException: 'nanoseconds must be non negative value and lessor than 999,999,999. Parameter name: nanoseconds

It seems MsgPack-CLI version 1.0 faults for certain values of DateTime.
Fails: 1969-12-31T23:59:59.001 to 1969-12-31T23:59:59.999
Works: 1969-12-31T23:59:59.000
Works: 1970-01-01

It always seems to work after 1970-01-01 and always fail to serialize dates before 1970-01-01 if and only if the milliseconds are non-zero.

    public class MyClass
    {
        public DateTime MyDate;
    }

    public static void TestBrokenMessagePack()
    {
        var serializerMPMyClass = SerializationContext.Default.GetSerializer<MyClass>();
        using (var stream = new MemoryStream())
        {
            var my = new MyClass
            {
                MyDate =
                DateTime.Parse("1969-12-31T23:59:59.001")
            };
            serializerMPMyClass.Pack(stream, my); // << This line faults
        }
    }
@yfakariya yfakariya added the bug Detected as bug label Jul 16, 2018
@yfakariya
Copy link
Member

Thank you for reporting. I will investigate this.

@yfakariya
Copy link
Member

It looks a bug for conversion for new timestamp type, but this failure caused by unintended breaking change for date time serialization. I will add mitigation to this with timestamp conversion related bug fix.

yfakariya added a commit that referenced this issue Sep 5, 2018
If the date time is before Unix epoc and it has subsecond value,
internal divrem operation returns negative remains and it causes exception.
This commit add adjustment for this situation.
yfakariya added a commit that referenced this issue Sep 9, 2018
If the date time is before Unix epoc and it has subsecond value,
internal divrem operation returns negative remains and it causes exception.
This commit add adjustment for this situation.
yfakariya added a commit that referenced this issue Sep 9, 2018
If the date time is before Unix epoc and it has subsecond value,
internal divrem operation returns negative remains and it causes exception.
This commit add adjustment for this situation.
yfakariya added a commit that referenced this issue Sep 9, 2018
If the date time is before Unix epoc and it has subsecond value,
internal divrem operation returns negative remains and it causes exception.
This commit add adjustment for this situation.
yfakariya added a commit that referenced this issue Nov 7, 2018
Fix #296 with new compatibility options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Detected as bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants