From f6d72fa79f28830bc641551c35e1bddd2328a407 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Tue, 14 May 2019 02:42:44 +0800 Subject: [PATCH] Fix assertion fail When fileSize == 0, the second index could be smaller than the first index, thus trigger the assert check in IndexInterval constructor. Closes #10611. --- src/base/bittorrent/torrentinfo.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/base/bittorrent/torrentinfo.cpp b/src/base/bittorrent/torrentinfo.cpp index ca121ab20..ab25782c6 100644 --- a/src/base/bittorrent/torrentinfo.cpp +++ b/src/base/bittorrent/torrentinfo.cpp @@ -340,8 +340,13 @@ TorrentInfo::PieceRange TorrentInfo::filePieces(int fileIndex) const const libt::file_storage &files = nativeInfo()->files(); const auto fileSize = files.file_size(fileIndex); const auto fileOffset = files.file_offset(fileIndex); - return makeInterval(static_cast(fileOffset / pieceLength()), - static_cast((fileOffset + fileSize - 1) / pieceLength())); + + const int beginIdx = (fileOffset / pieceLength()); + const int endIdx = ((fileOffset + fileSize - 1) / pieceLength()); + + if (fileSize <= 0) + return {beginIdx, 0}; + return makeInterval(beginIdx, endIdx); } void TorrentInfo::renameFile(const int index, const QString &newPath)