mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-12 08:16:16 -07:00
Prevent loading resume data with inconsistent ID
This commit is contained in:
parent
299f981441
commit
cbc0ef860b
1 changed files with 46 additions and 37 deletions
|
@ -4480,23 +4480,19 @@ void Session::startUpTorrents()
|
||||||
const lt::info_hash_t infoHash = (resumeData.ltAddTorrentParams.ti
|
const lt::info_hash_t infoHash = (resumeData.ltAddTorrentParams.ti
|
||||||
? resumeData.ltAddTorrentParams.ti->info_hashes()
|
? resumeData.ltAddTorrentParams.ti->info_hashes()
|
||||||
: resumeData.ltAddTorrentParams.info_hashes);
|
: resumeData.ltAddTorrentParams.info_hashes);
|
||||||
if (infoHash.has_v1() && infoHash.has_v2())
|
const bool isHybrid = infoHash.has_v1() && infoHash.has_v2();
|
||||||
{
|
|
||||||
const auto torrentIDv1 = TorrentID::fromInfoHash(lt::info_hash_t(infoHash.v1));
|
|
||||||
const auto torrentIDv2 = TorrentID::fromInfoHash(infoHash);
|
const auto torrentIDv2 = TorrentID::fromInfoHash(infoHash);
|
||||||
|
const auto torrentIDv1 = TorrentID::fromInfoHash(lt::info_hash_t(infoHash.v1));
|
||||||
if (torrentID == torrentIDv2)
|
if (torrentID == torrentIDv2)
|
||||||
{
|
{
|
||||||
if (indexedTorrents.contains(torrentIDv1))
|
if (isHybrid && indexedTorrents.contains(torrentIDv1))
|
||||||
{
|
{
|
||||||
// if we has no metadata trying to find it in alternative "resume data"
|
// if we don't have metadata, try to find it in alternative "resume data"
|
||||||
if (!resumeData.ltAddTorrentParams.ti)
|
if (!resumeData.ltAddTorrentParams.ti)
|
||||||
{
|
{
|
||||||
const std::optional<LoadTorrentParams> loadAltResumeDataResult = startupStorage->load(torrentIDv1);
|
const std::optional<LoadTorrentParams> loadAltResumeDataResult = startupStorage->load(torrentIDv1);
|
||||||
if (loadAltResumeDataResult)
|
if (loadAltResumeDataResult)
|
||||||
{
|
resumeData.ltAddTorrentParams.ti = loadAltResumeDataResult->ltAddTorrentParams.ti;
|
||||||
LoadTorrentParams altResumeData = *loadAltResumeDataResult;
|
|
||||||
resumeData.ltAddTorrentParams.ti = altResumeData.ltAddTorrentParams.ti;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove alternative "resume data" and skip the attempt to load it
|
// remove alternative "resume data" and skip the attempt to load it
|
||||||
|
@ -4504,7 +4500,7 @@ void Session::startUpTorrents()
|
||||||
skippedIDs.insert(torrentIDv1);
|
skippedIDs.insert(torrentIDv1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else if (torrentID == torrentIDv1)
|
||||||
{
|
{
|
||||||
torrentID = torrentIDv2;
|
torrentID = torrentIDv2;
|
||||||
needStore = true;
|
needStore = true;
|
||||||
|
@ -4517,15 +4513,28 @@ void Session::startUpTorrents()
|
||||||
const std::optional<LoadTorrentParams> loadPreferredResumeDataResult = startupStorage->load(torrentID);
|
const std::optional<LoadTorrentParams> loadPreferredResumeDataResult = startupStorage->load(torrentID);
|
||||||
if (loadPreferredResumeDataResult)
|
if (loadPreferredResumeDataResult)
|
||||||
{
|
{
|
||||||
LoadTorrentParams preferredResumeData = *loadPreferredResumeDataResult;
|
|
||||||
std::shared_ptr<lt::torrent_info> ti = resumeData.ltAddTorrentParams.ti;
|
std::shared_ptr<lt::torrent_info> ti = resumeData.ltAddTorrentParams.ti;
|
||||||
if (!preferredResumeData.ltAddTorrentParams.ti)
|
resumeData = *loadPreferredResumeDataResult;
|
||||||
preferredResumeData.ltAddTorrentParams.ti = ti;
|
if (!resumeData.ltAddTorrentParams.ti)
|
||||||
|
resumeData.ltAddTorrentParams.ti = ti;
|
||||||
resumeData = preferredResumeData;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LogMsg(tr("Failed to resume torrent: inconsistent torrent ID is detected. Torrent: \"%1\"")
|
||||||
|
.arg(torrentID.toString()), Log::WARNING);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
const lt::sha1_hash infoHash = (resumeData.ltAddTorrentParams.ti
|
||||||
|
? resumeData.ltAddTorrentParams.ti->info_hash()
|
||||||
|
: resumeData.ltAddTorrentParams.info_hash);
|
||||||
|
if (torrentID != TorrentID::fromInfoHash(infoHash))
|
||||||
|
{
|
||||||
|
LogMsg(tr("Failed to resume torrent: inconsistent torrent ID is detected. Torrent: \"%1\"")
|
||||||
|
.arg(torrentID.toString()), Log::WARNING);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue