1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-27 18:18:10 +00:00

fix: crash in tr_file_priorities::filePriority() (#2291)

Fixes #2262.
This commit is contained in:
Charles Kerr 2021-12-09 15:38:18 -06:00 committed by GitHub
parent d5aead4b41
commit f39a1e45a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -579,30 +579,37 @@ static void onTrackerResponse(tr_torrent* tor, tr_tracker_event const* event, vo
**** ****
***/ ***/
static void tr_torrentInitFileOffsets(tr_torrent* tor) static void torrentStart(tr_torrent* tor, bool bypass_queue);
{
auto offset = uint64_t{ 0 };
static void tr_torrentFireMetadataCompleted(tr_torrent* tor);
static void torrentInitFromInfoDict(tr_torrent* tor)
{
tor->initSizes(tor->info.totalSize, tor->info.pieceSize);
tor->completion = tr_completion{ tor, tor };
tr_sha1(tor->obfuscatedHash, "req2", 4, tor->info.hash, SHA_DIGEST_LENGTH, nullptr);
// init file offsets
auto offset = uint64_t{ 0 };
for (tr_file_index_t i = 0, n = tor->fileCount(); i < n; ++i) for (tr_file_index_t i = 0, n = tor->fileCount(); i < n; ++i)
{ {
auto& file = tor->file(i); auto& file = tor->file(i);
file.priv.offset = offset; file.priv.offset = offset;
offset += file.length; offset += file.length;
} }
tor->fpm_.reset(tor->info);
tor->file_priorities_.reset(&tor->fpm_);
tor->files_wanted_.reset(&tor->fpm_);
tor->dnd_pieces_ = tr_bitfield{ tor->info.pieceCount };
tor->checked_pieces_ = tr_bitfield{ tor->info.pieceCount };
} }
static void torrentStart(tr_torrent* tor, bool bypass_queue);
static void tr_torrentFireMetadataCompleted(tr_torrent* tor);
void tr_torrentGotNewInfoDict(tr_torrent* tor) void tr_torrentGotNewInfoDict(tr_torrent* tor)
{ {
tor->initSizes(tor->info.totalSize, tor->info.pieceSize); torrentInitFromInfoDict(tor);
tor->completion = tr_completion{ tor, tor };
tr_torrentInitFileOffsets(tor);
tr_peerMgrOnTorrentGotMetainfo(tor); tr_peerMgrOnTorrentGotMetainfo(tor);
tr_torrentFireMetadataCompleted(tor); tr_torrentFireMetadataCompleted(tor);
} }
@ -654,25 +661,17 @@ static void refreshCurrentDir(tr_torrent* tor);
static void torrentInit(tr_torrent* tor, tr_ctor const* ctor) static void torrentInit(tr_torrent* tor, tr_ctor const* ctor)
{ {
static auto next_unique_id = int{ 1 };
auto const lock = tor->unique_lock(); auto const lock = tor->unique_lock();
tr_session* session = tr_ctorGetSession(ctor); tr_session* session = tr_ctorGetSession(ctor);
TR_ASSERT(session != nullptr); TR_ASSERT(session != nullptr);
static int nextUniqueId = 1;
tor->fpm_.reset(tor->info);
tor->file_priorities_.reset(&tor->fpm_);
tor->files_wanted_.reset(&tor->fpm_);
tor->session = session; tor->session = session;
tor->uniqueId = nextUniqueId++; tor->uniqueId = next_unique_id++;
tor->queuePosition = tr_sessionCountTorrents(session); tor->queuePosition = tr_sessionCountTorrents(session);
tor->dnd_pieces_ = tr_bitfield{ tor->info.pieceCount }; torrentInitFromInfoDict(tor);
tor->checked_pieces_ = tr_bitfield{ tor->info.pieceCount };
tr_sha1(tor->obfuscatedHash, "req2", 4, tor->info.hash, SHA_DIGEST_LENGTH, nullptr);
char const* dir = nullptr; char const* dir = nullptr;
if (tr_ctorGetDownloadDir(ctor, TR_FORCE, &dir) || tr_ctorGetDownloadDir(ctor, TR_FALLBACK, &dir)) if (tr_ctorGetDownloadDir(ctor, TR_FORCE, &dir) || tr_ctorGetDownloadDir(ctor, TR_FALLBACK, &dir))
@ -703,10 +702,6 @@ static void torrentInit(tr_torrent* tor, tr_ctor const* ctor)
tr_torrentSetDateAdded(tor, tr_time()); /* this is a default value to be overwritten by the resume file */ tr_torrentSetDateAdded(tor, tr_time()); /* this is a default value to be overwritten by the resume file */
tor->initSizes(tor->info.totalSize, tor->info.pieceSize);
tor->completion = tr_completion{ tor, tor };
tr_torrentInitFileOffsets(tor);
// tr_torrentLoadResume() calls a lot of tr_torrentSetFoo() methods // tr_torrentLoadResume() calls a lot of tr_torrentSetFoo() methods
// that set things as dirty, but... these settings being loaded are // that set things as dirty, but... these settings being loaded are
// the same ones that would be saved back again, so don't let them // the same ones that would be saved back again, so don't let them