From 24da51ffa03665daf216b532408ce81693346d3a Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Fri, 1 Sep 2023 00:18:03 +0800 Subject: [PATCH] Perform type conversion properly Closes #19521. PR #19525. --- src/base/utils/io.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/base/utils/io.cpp b/src/base/utils/io.cpp index 6eba4dd48..2be80549b 100644 --- a/src/base/utils/io.cpp +++ b/src/base/utils/io.cpp @@ -28,6 +28,9 @@ #include "io.h" +#include +#include + #include #include @@ -88,8 +91,14 @@ nonstd::expected Utils::IO::readFile(const Pat .arg(file.fileName(), QString::number(fileSize), QString::number(maxSize)); return nonstd::make_unexpected(ReadError {ReadError::ExceedSize, message}); } + if (!std::in_range(fileSize)) + { + const QString message = QCoreApplication::translate("Utils::IO", "File size exceeds data size limit. File: \"%1\". File size: %2. Array limit: %3") + .arg(file.fileName(), QString::number(fileSize), QString::number(std::numeric_limits::max())); + return nonstd::make_unexpected(ReadError {ReadError::ExceedSize, message}); + } - QByteArray ret {fileSize, Qt::Uninitialized}; + QByteArray ret {static_cast(fileSize), Qt::Uninitialized}; const qint64 actualSize = file.read(ret.data(), fileSize); if (actualSize < 0)