[Mono-list] MonoTorrent error + fix

Will Murnane will.murnane at gmail.com
Tue Jan 16 05:15:58 EST 2007

I'm writing a BitTorrent client using the bitsharp library, and I
encountered an error with a torrent that has total file size > 4GB.
The problem occurs on line 124 of PieceMessage.cs:

long pieceOffset = this.startOffset + this.PieceIndex *

this.PieceIndex and this.fileManager.PieceLength are both 32-bit ints;
when they're multiplied an overflow can result, and pass an
(overflowed) negative value to FileManager.Read.  My suggestion is to
cast one of them to long before the multiply is performed:

long pieceOffset = this.startOffset + (long)this.PieceIndex *

That should fix the problem.  Here's a screenshot of the debugger
helping me find the problem:

Last, thanks for the cool library!  I was afraid I'd have to write my
own bittorrent library to get this working, but bitsharp is working
(mostly :-P) nicely.


More information about the Mono-list mailing list