1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-25 22:14:32 +00:00

Merge pull request #9278 from Couchy/torrent_file_error_handling

Improve error handling when loading torrent files
This commit is contained in:
Mike Tzou 2018-08-12 00:21:56 +08:00 committed by GitHub
commit f44ff63361
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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();
} }