mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-04 14:42:29 -06:00
Don't read unlimited data from files
It now guards against reading infinite files such as `/dev/zero`. And most readings are bound with a (lax) limit. As a side effect, more checking are done when reading a file and overall the reading procedure is more robust. PR #19095.
This commit is contained in:
@@ -33,6 +33,8 @@
|
||||
|
||||
#include <libtorrent/fwd.hpp>
|
||||
|
||||
#include <QIODevice>
|
||||
|
||||
#include "base/3rdparty/expected.hpp"
|
||||
#include "base/pathfwd.h"
|
||||
|
||||
@@ -81,6 +83,23 @@ namespace Utils::IO
|
||||
int m_bufferSize = 0;
|
||||
};
|
||||
|
||||
struct ReadError
|
||||
{
|
||||
enum Code
|
||||
{
|
||||
NotExist,
|
||||
ExceedSize,
|
||||
SizeMismatch
|
||||
};
|
||||
|
||||
Code status = {};
|
||||
QString message;
|
||||
};
|
||||
|
||||
// TODO: define a specific type for `additionalMode`
|
||||
// providing `size` is explicit and is strongly recommended
|
||||
nonstd::expected<QByteArray, ReadError> readFile(const Path &path, qint64 size, QIODevice::OpenMode additionalMode = {});
|
||||
|
||||
nonstd::expected<void, QString> saveToFile(const Path &path, const QByteArray &data);
|
||||
nonstd::expected<void, QString> saveToFile(const Path &path, const lt::entry &data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user