mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-19 21:03:30 -07:00
Avoid allocating large memory when loading a .torrent file
`QIODevice::read(qint64 maxSize)` will allocate full `maxSize` of memory no matter what the real file size was, this caused users to experience out-of-memory exception on 32-bit qbt. Also handle the OOM execption if it still fails. Closes #9064, #9075, #9130, #9239, #9246, #9279.
This commit is contained in:
parent
e59841d35c
commit
3808b5df16
1 changed files with 10 additions and 2 deletions
|
@ -112,10 +112,18 @@ TorrentInfo TorrentInfo::loadFromFile(const QString &path, QString *error) noexc
|
||||||
return TorrentInfo();
|
return TorrentInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
const QByteArray data = file.read(fileSizeLimit);
|
QByteArray data;
|
||||||
|
try {
|
||||||
|
data = file.readAll();
|
||||||
|
}
|
||||||
|
catch (const std::bad_alloc &e) {
|
||||||
|
if (error)
|
||||||
|
*error = tr("Torrent file read error: %1").arg(e.what());
|
||||||
|
return TorrentInfo();
|
||||||
|
}
|
||||||
if (data.size() != file.size()) {
|
if (data.size() != file.size()) {
|
||||||
if (error)
|
if (error)
|
||||||
*error = tr("Torrent file read error");
|
*error = tr("Torrent file read error: size mismatch");
|
||||||
return TorrentInfo();
|
return TorrentInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue