Skip to content

Commit

Permalink
[core] Verifies valid and absolute HttpSeed urls on load
Browse files Browse the repository at this point in the history
Invalid urls would fail to parse in Mode.DownloadLogic throwing an unhandled exception. This adds a check for a well formed and absolute uri before adding them to the HttpSeeds
  • Loading branch information
phil-scott-78 authored and alanmcgovern committed Apr 1, 2021
1 parent 423ea9f commit 61bcc56
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
16 changes: 15 additions & 1 deletion src/MonoTorrent.Tests/Common/TorrentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ public void StartUp ()
{ "created by", new BEncodedString ($"MonoTorrent/{VersionInfo.ClientVersion}") },
{ "encoding", new BEncodedString ("UTF-8") },
{ "info", CreateInfoDict () },
{ "private", new BEncodedString ("1") }
{ "private", new BEncodedString ("1") },
{ "url-list", new BEncodedList() {
new BEncodedString ("https://example.com/8/items/"),
new BEncodedString ("/8/items/"), // this should be ignored on loading
} }
};
torrent = Torrent.Load (torrentInfo);
}
Expand Down Expand Up @@ -256,6 +260,16 @@ public void Files ()
Assert.AreEqual (80000, torrent.Files[3].Length);
}

/// <summary>
///
/// </summary>
[Test]
public void HttpSeeds ()
{
Assert.IsTrue (torrent.HttpSeeds.Count == 1);
Assert.AreEqual("https://example.com/8/items/", torrent.HttpSeeds[0]);
}

[Test]
public void InvalidPath ()
{
Expand Down
12 changes: 8 additions & 4 deletions src/MonoTorrent/MonoTorrent/Torrent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Expand Down Expand Up @@ -676,10 +676,14 @@ void LoadInternal (BEncodedDictionary torrentInformation, InfoHash infoHash)

case ("url-list"):
if (keypair.Value is BEncodedString httpSeedString) {
HttpSeeds.Add (httpSeedString.Text);
if (Uri.IsWellFormedUriString (httpSeedString.Text, UriKind.Absolute)) {
HttpSeeds.Add (httpSeedString.Text);
}
} else if (keypair.Value is BEncodedList httpSeedList) {
foreach (BEncodedString str in httpSeedList)
HttpSeeds.Add (str.Text);
if (Uri.IsWellFormedUriString (str.Text, UriKind.Absolute)) {
HttpSeeds.Add (str.Text);
}
}
break;

Expand Down

0 comments on commit 61bcc56

Please sign in to comment.