Data Validation needed on Peers received from tracker #26

kill-9-me opened this Issue Nov 1, 2012 · 3 comments


None yet
2 participants

A peer without a port from the tracker results in the following exception. This can and does routinely happen. Especially on open source torrents (IE: Ubuntu)

System.ArgumentOutOfRangeException was unhandled by user code
Message=Specified argument was out of the range of valid values.
Parameter name: port
at System.Net.IPEndPoint..ctor(IPAddress address, Int32 port)
at MonoTorrent.Client.Connections.IPV4Connection..ctor(Uri uri) in c:\Users\xxx\Documents\GitHub\xxx\MonoTorrent\MonoTorrent.Client\PeerConnections\TCPConnection.cs:line 83

gen3ric commented Nov 4, 2012

The exception occurs in the constructor when trying to create an IPEndpoint with a port of -1. I have a workaround in my fork, it seems to be working though I think Alan would want it to be prettier before doing a pull.

Could you point me to the commit in your fork that contains the workaround? Looking through your commit history all I see is the check to fix the Stopping bug for non-responsive trackers. (It's entirely possible I'm just blind today)

This fixed my issue. It's a bit hackish but it puts port validation on TCP connections. When a non-valid port is used it returns a null value which is gracefully handled elsewhere.

@@ -29,6 +29,11 @@ public static void RegisterTypeForProtocol(string protocol, Type connectionType)

         public static IConnection Create(Uri connectionUri)
+            if (connectionUri.Scheme == "tcp" && (connectionUri.Port < 1 || connectionUri.Port > 65535))
+            {
+                return null;
+            }
             if (connectionUri == null)
                 throw new ArgumentNullException("connectionUrl");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment