diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9ce35be..9e05b3a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -134,7 +134,6 @@ jobs: -retries 2 \ -compact0-fallback \ -insecure \ - -proxy socks5://localhost:4444 \ -sam \ -doh-servers "https://cloudflare-dns.com/dns-query,https://dns.google/dns-query,https://doh.dns.sb/dns-query" \ -dns-timeout 5s \ diff --git a/tests/TrackerChecker.Tests/ProtocolRegressionTests.cs b/tests/TrackerChecker.Tests/ProtocolRegressionTests.cs index a589c8d..0a93c37 100644 --- a/tests/TrackerChecker.Tests/ProtocolRegressionTests.cs +++ b/tests/TrackerChecker.Tests/ProtocolRegressionTests.cs @@ -16,6 +16,24 @@ public void Bencode_ValidAnnounceResponse_IsAccepted() Assert.True(global::TrackerChecker.TrackerChecker.BdecodeSimple(response)); } + [Fact] + public void Bencode_AnnounceResponseWithoutPeers_IsAccepted() + { + // numwant=0 trackers may omit peers entirely while still accepting + // the announce and returning a valid interval. + var response = Encoding.ASCII.GetBytes("d8:intervali180ee"); + + Assert.True(global::TrackerChecker.TrackerChecker.BdecodeSimple(response)); + } + + [Fact] + public void Bencode_InvalidCompactPeerLength_IsRejected() + { + var response = Encoding.ASCII.GetBytes("d8:intervali180e5:peers1:xe"); + + Assert.False(global::TrackerChecker.TrackerChecker.BdecodeSimple(response)); + } + [Fact] public void Bencode_FailureReason_IsRejected() { diff --git a/trackerchecker.cs b/trackerchecker.cs index ef6052e..c0a1e83 100644 --- a/trackerchecker.cs +++ b/trackerchecker.cs @@ -1353,7 +1353,6 @@ internal static bool BdecodeSimple(ReadOnlySpan data) var pos = 1; var hasInterval = false; - var hasPeers = false; var hasFailureReason = false; while (pos < data.Length && data[pos] != (byte)'e') @@ -1388,7 +1387,6 @@ internal static bool BdecodeSimple(ReadOnlySpan data) if (!SkipBencodeValue(data, ref pos, 0)) return false; } else return false; - hasPeers = true; continue; } @@ -1397,7 +1395,6 @@ internal static bool BdecodeSimple(ReadOnlySpan data) if (!char.IsAsciiDigit((char)data[pos]) || !TryReadBencodeString(data, ref pos, out var peers6) || peers6.Length % 18 != 0) return false; - hasPeers = true; continue; } @@ -1406,7 +1403,9 @@ internal static bool BdecodeSimple(ReadOnlySpan data) } // A failure reason is an explicit tracker rejection, never an ALIVE response. - return !hasFailureReason && hasInterval && hasPeers && + // Trackers may omit peers when numwant=0 or when no peers are available. + // Any peer payload that is present is still validated above. + return !hasFailureReason && hasInterval && pos == data.Length - 1 && data[pos] == (byte)'e'; }