Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
18 changes: 18 additions & 0 deletions tests/TrackerChecker.Tests/ProtocolRegressionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
7 changes: 3 additions & 4 deletions trackerchecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,6 @@ internal static bool BdecodeSimple(ReadOnlySpan<byte> data)

var pos = 1;
var hasInterval = false;
var hasPeers = false;
var hasFailureReason = false;

while (pos < data.Length && data[pos] != (byte)'e')
Expand Down Expand Up @@ -1388,7 +1387,6 @@ internal static bool BdecodeSimple(ReadOnlySpan<byte> data)
if (!SkipBencodeValue(data, ref pos, 0)) return false;
}
else return false;
hasPeers = true;
continue;
}

Expand All @@ -1397,7 +1395,6 @@ internal static bool BdecodeSimple(ReadOnlySpan<byte> data)
if (!char.IsAsciiDigit((char)data[pos]) ||
!TryReadBencodeString(data, ref pos, out var peers6) || peers6.Length % 18 != 0)
return false;
hasPeers = true;
continue;
}

Expand All @@ -1406,7 +1403,9 @@ internal static bool BdecodeSimple(ReadOnlySpan<byte> 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';
}

Expand Down
Loading