cefsharp / CefSharp

.NET (WPF and Windows Forms) bindings for the Chromium Embedded Framework
http://cefsharp.github.io/
Other
9.83k stars 2.92k forks source link

Cookie.Expiry ArgumentOutOfRangeException crash caused by conversion of extremely large date time #4272

Closed mbragg12 closed 1 year ago

mbragg12 commented 1 year ago

Bug Report

mbragg12 commented 1 year ago

@amaitland I can look at making a PR for this issue if desired. Just need to know if you would rather sanitize the values in static Cookie FromNative or put a max value check in FromBaseTimeToDateTime.

amaitland commented 1 year ago

759797148870000000 is the exact value that it was setting.

Do you happen to know what date this converts to?

put a max value check in FromBaseTimeToDateTime.

Let's go with this option, thanks 👍

mbragg12 commented 1 year ago

Do you happen to know what date this converts to?

No clue. It doesn't seem like a valid date but we have seen it in a few DB's from a couple sites now. So Chromium thought it was valid for something at some point.

put a max value check in FromBaseTimeToDateTime.

Let's go with this option, thanks 👍

This is the check we are using as a fix tentatively. Waiting on feedback, to make sure. Look good to you?

         public static DateTime FromBaseTimeToDateTime(long val)
         {
            //FileTime max value is 2650467743999999999
            if (val > 265046774399999999)
                val = 265046774399999999;

             return DateTime.FromFileTime(val * 10);
         }
amaitland commented 1 year ago

Thanks, I'd like to use MaxValue if at all possible, make for easier comparison.

See what you think of https://github.com/cefsharp/CefSharp/commit/9dc158693d6aa25cc6905ea10db90f1f548857e5

Unit tests will need to be added still.

mbragg12 commented 1 year ago

I like yours better. Much cleaner.

amaitland commented 1 year ago

This should be fixed in 106.0.290.

Adding a custom conversion implementation should also be possible see https://github.com/cefsharp/CefSharp/commit/710508b0ff592c0de6266501c23bf839310a5fdd#diff-4f6c2a768c993bf3274c45a7cfeda5bdea738e11130e6dc01daec795a6a07931R25