From 2ac773385f9852a165c3ae45e1bef02fb684f83d Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Thu, 23 Nov 2017 22:18:38 +0300 Subject: [PATCH] Clamp utime range (Wnd) --- Utilities/File.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Utilities/File.cpp b/Utilities/File.cpp index 6c700e1625..f9c1cf7425 100644 --- a/Utilities/File.cpp +++ b/Utilities/File.cpp @@ -75,10 +75,25 @@ static time_t to_time(const FILETIME& ft) static FILETIME from_time(s64 _time) { - const ullong wtime = (_time + 11644473600ULL) * 10000000ULL; FILETIME result; - result.dwLowDateTime = static_cast(wtime); - result.dwHighDateTime = static_cast(wtime >> 32); + + if (_time <= -11644473600ll) + { + result.dwLowDateTime = 0; + result.dwHighDateTime = 0; + } + else if (_time > INT64_MAX / 10000000ll - 11644473600ll) + { + result.dwLowDateTime = 0xffffffff; + result.dwHighDateTime = 0x7fffffff; + } + else + { + const ullong wtime = (_time + 11644473600ull) * 10000000ull; + result.dwLowDateTime = static_cast(wtime); + result.dwHighDateTime = static_cast(wtime >> 32); + } + return result; }