From 42f37a18524763db9fa40f096b1c465d40fd2042 Mon Sep 17 00:00:00 2001 From: Martchus Date: Sat, 22 Dec 2018 02:46:55 +0100 Subject: [PATCH] Fix warning about implicit conversion --- io/passwordfile.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/io/passwordfile.cpp b/io/passwordfile.cpp index f9a378e..dd01b00 100644 --- a/io/passwordfile.cpp +++ b/io/passwordfile.cpp @@ -319,10 +319,17 @@ void PasswordFile::load() if (remainingSize < 8) { throw ParsingException("File is truncated (decompressed size expected)."); } - uLongf decompressedSize = ConversionUtilities::LE::toUInt64(decryptedData.data()); + if (remainingSize > numeric_limits::max()) { + throw CryptoException("Size exceeds limit."); + } + const auto rawDecompressedSize = ConversionUtilities::LE::toUInt64(decryptedData.data()); + if (rawDecompressedSize > numeric_limits::max()) { + throw ParsingException("Decompressed size exceeds limit."); + } + auto decompressedSize = static_cast(rawDecompressedSize); rawData.resize(decompressedSize); - switch (uncompress( - reinterpret_cast(rawData.data()), &decompressedSize, reinterpret_cast(decryptedData.data() + 8), remainingSize - 8)) { + switch (uncompress(reinterpret_cast(rawData.data()), &decompressedSize, reinterpret_cast(decryptedData.data() + 8), + static_cast(remainingSize - 8))) { case Z_MEM_ERROR: throw ParsingException("Decompressing failed. The source buffer was too small."); case Z_BUF_ERROR: