From 48637c687c4ea3a7f5c56f7b2f88d2cb60536fe6 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Tue, 30 Jun 2020 14:32:48 -0400 Subject: [PATCH] Windows: Fix CefCookieVisitor crash on invalid date (fixes issue #2927) --- libcef/common/time_impl.cc | 10 ++++++++++ tests/ceftests/cookie_unittest.cc | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/libcef/common/time_impl.cc b/libcef/common/time_impl.cc index 1d47c5c33..67f31635c 100644 --- a/libcef/common/time_impl.cc +++ b/libcef/common/time_impl.cc @@ -20,6 +20,16 @@ void cef_time_to_basetime(const cef_time_t& cef_time, base::Time& time) { } void cef_time_from_basetime(const base::Time& time, cef_time_t& cef_time) { +#if defined(OS_WIN) + int64_t t = time.ToDeltaSinceWindowsEpoch().InMicroseconds(); + // From MSDN, FILETIME "Contains a 64-bit value representing the number of + // 100-nanosecond intervals since January 1, 1601 (UTC)." This value must + // be less than 0x8000000000000000. Otherwise, the function + // FileTimeToSystemTime fails. + if (t < 0 || static_cast(t * 10) >= 0x8000000000000000) + return; +#endif + base::Time::Exploded exploded; time.UTCExplode(&exploded); cef_time.year = exploded.year; diff --git a/tests/ceftests/cookie_unittest.cc b/tests/ceftests/cookie_unittest.cc index 890286aa6..e4672a1c7 100644 --- a/tests/ceftests/cookie_unittest.cc +++ b/tests/ceftests/cookie_unittest.cc @@ -569,7 +569,9 @@ class CookieTestJSHandler : public TestHandler { std::string page = "" "" "COOKIE TEST1"; AddResource(kCookieJSUrl1, page, "text/html");