Possible bug in MultiFileCache
ClosedPublic

Authored by trufanov on Jun 14 2020, 12:53 PM.

Details

Reviewers
stikonas
Summary

Once I've taken a look in ~/.local/share/ktorrent/ folder and realized that few (2 of 400) of my torrents have too big ./dnd/ subfolders there. These torrents contained multiple video files (TV series) with external subtitles (10-30 Kb text files) on different languages. I downloaded only a few series from these torrents and subtitles only for russian. So there were many file[N].dnd files in dnd subfolder that kept cache of data for files I'm not going to download, but they still were downloaded as they were in the same piece of torrent stream chunk with files I needed. That's ok, but some file[N].dnd which corresponded to subtitle files were too big. Their size was close to the size of the chunk declared in torrent file (4 Mb). They contained whole subtitle data plus some trash at the end. And they supposed to be equal or less than subtitle file (few kilobytes).

I investigated the code and I think, that there is a mistake in MultiFileCache source. piece_len is compared instead of piece_off in one of 4 cases of calculateOffsetAndLength(). There is no *_len variable usage in other 3 for statements without sum with *_off variable. Looking and comment in code I think author meant to use piece_off and just copy/paste wrong variable. piece_len is often much smaller than piece_off and this comparison might be true in cases it shouldn't.

The problem is that I couldn't reproduce this bug. I've redownloaded the torrents with wrong cache of dnd files and selected same files to download, but this time cache was created properly. Thus I can't say if proposed change fixes this bug or have any relation to it. But I can say that after this patch KTorrent works as usual and this code is really executed during download of data.

So I'm suggesting the fix based on my understanding of the code...

Diff Detail

Repository
R472 KTorrent Library
Lint
Lint Skipped
Unit
Unit Tests Skipped
trufanov requested review of this revision.Jun 14 2020, 12:53 PM
trufanov created this revision.
stikonas accepted this revision.Jun 14 2020, 1:04 PM

Yeah, looking at the code I think you are right.

Maybe consider creating 2.2 branch? Push it there an merge to master.

Also, I think at this stage we are supposed to do merge requests on invent.kde.org

This revision is now accepted and ready to land.Jun 14 2020, 1:04 PM
trufanov closed this revision.Jun 25 2020, 11:13 AM

Commited: https://invent.kde.org/network/libktorrent/-/commit/5b0abf8378d497c5a8881771518df6a02404d031

Could you please clarify a process? Shall I pass the review on phabricator then create a pull request on Invent? Or just create a Pull Request on Invent?

Commited: https://invent.kde.org/network/libktorrent/-/commit/5b0abf8378d497c5a8881771518df6a02404d031

Could you please clarify a process? Shall I pass the review on phabricator then create a pull request on Invent? Or just create a Pull Request on Invent?

No, I think Phabricator is going away. I think now you do merge request on Invent, pass review and then update your MR with new changes if required (might need force pushing) and merge it.