Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception in SimpleTorrentManager.GetPeers #715

Open
johnsu opened this issue Jan 31, 2025 · 0 comments · May be fixed by #716
Open

Exception in SimpleTorrentManager.GetPeers #715

johnsu opened this issue Jan 31, 2025 · 0 comments · May be fixed by #716

Comments

@johnsu
Copy link

johnsu commented Jan 31, 2025

I have a tracker server that handles many announces in quick succession.

System.ArgumentException: Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.
   at System.Buffer.BlockCopy(Array src, Int32 srcOffset, Array dst, Int32 dstOffset, Int32 count)
   at MonoTorrent.TrackerServer.SimpleTorrentManager.GetPeers(BEncodedDictionary response, Int32 count, Boolean compact, AddressFamily addressFamily) in C:\Projects\monotorrent\src\MonoTorrent.Client\MonoTorrent.TrackerServer\SimpleTorrentManager.cs:line 179
   at MonoTorrent.TrackerServer.TrackerServer.ListenerReceivedAnnounce(Object sender, AnnounceRequest e) in C:\Projects\monotorrent\src\MonoTorrent.Client\MonoTorrent.TrackerServer\TrackerServer.cs:line 268
   at MonoTorrent.Connections.TrackerServer.TrackerListener.Handle(NameValueCollection collection, IPAddress remoteAddress, Boolean isScrape) in C:\Projects\monotorrent\src\MonoTorrent.Trackers\MonoTorrent.Connections.TrackerServer\TrackerListener.cs:line 65

It appears to happen if you announce an ipv6 address then immediately announce the same torrent with an ipv4 address. The PeerList is remains the same length thus is not updated but the address family switches so the ipv6 peerlist will overflow the the buffer which was allocated for ipv4 stride sizes.

(int stride, Dictionary<object, Peer> peers, BEncodedString peersKey) = addressFamily switch {

Buffer.BlockCopy (current.CompactEntry, 0, compactResponse!, (total - 1) * current.CompactEntry.Length, current.CompactEntry.Length);

@johnsu johnsu changed the title Exception in SimpleTorrentManager.GetPeers causes announces Exception in SimpleTorrentManager.GetPeers Feb 1, 2025
@johnsu johnsu linked a pull request Feb 1, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant