mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-31 03:50:20 -07: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:
parent
81bc910d68
commit
79ca2e145f
24 changed files with 370 additions and 199 deletions
|
@ -48,6 +48,7 @@
|
|||
#include "../logger.h"
|
||||
#include "../profile.h"
|
||||
#include "../utils/fs.h"
|
||||
#include "../utils/io.h"
|
||||
#include "rss_article.h"
|
||||
#include "rss_autodownloadrule.h"
|
||||
#include "rss_feed.h"
|
||||
|
@ -493,21 +494,21 @@ void AutoDownloader::processJob(const QSharedPointer<ProcessingJob> &job)
|
|||
|
||||
void AutoDownloader::load()
|
||||
{
|
||||
QFile rulesFile {(m_fileStorage->storageDir() / Path(RULES_FILE_NAME)).data()};
|
||||
const qint64 maxFileSize = 10 * 1024 * 1024;
|
||||
const auto readResult = Utils::IO::readFile((m_fileStorage->storageDir() / Path(RULES_FILE_NAME)), maxFileSize);
|
||||
if (!readResult)
|
||||
{
|
||||
if (readResult.error().status == Utils::IO::ReadError::NotExist)
|
||||
{
|
||||
loadRulesLegacy();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!rulesFile.exists())
|
||||
{
|
||||
loadRulesLegacy();
|
||||
}
|
||||
else if (rulesFile.open(QFile::ReadOnly))
|
||||
{
|
||||
loadRules(rulesFile.readAll());
|
||||
}
|
||||
else
|
||||
{
|
||||
LogMsg(tr("Couldn't read RSS AutoDownloader rules from %1. Error: %2")
|
||||
.arg(rulesFile.fileName(), rulesFile.errorString()), Log::CRITICAL);
|
||||
LogMsg((tr("Failed to read RSS AutoDownloader rules. %1").arg(readResult.error().message)), Log::WARNING);
|
||||
return;
|
||||
}
|
||||
|
||||
loadRules(readResult.value());
|
||||
}
|
||||
|
||||
void AutoDownloader::loadRules(const QByteArray &data)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue