From d48f6281af49b17d1f6d6802b8921c1aed38a713 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Fri, 19 May 2017 06:48:22 +0300 Subject: hardening & refactoring My latest obsession is integer overflows. --- src/utils/file.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'src/utils/file.cpp') diff --git a/src/utils/file.cpp b/src/utils/file.cpp index 4150685..f013d90 100644 --- a/src/utils/file.cpp +++ b/src/utils/file.cpp @@ -37,15 +37,12 @@ namespace pdb if (!GetFileSizeEx(handle.get(), &size)) throw error::windows(GetLastError()); - try - { - const msl::utilities::SafeInt safe_size{size.QuadPart}; - return static_cast(safe_size); - } - catch (const msl::utilities::SafeIntException&) - { - throw std::range_error{"invalid file size"}; - } + std::size_t result = 0; + + if (!msl::utilities::SafeCast(size.QuadPart, result)) + throw std::runtime_error{"unsupported file size"}; + + return result; } } } -- cgit v1.2.3