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...