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)