diff --git a/magneticod/bittorrent/operations.go b/magneticod/bittorrent/operations.go index 7b3352a..73525b8 100644 --- a/magneticod/bittorrent/operations.go +++ b/magneticod/bittorrent/operations.go @@ -150,7 +150,15 @@ func (ms *MetadataSink) awaitMetadata(infoHash metainfo.Hash, peer Peer) { ) return } + + // The messages we are interested in have the length of AT LEAST two bytes + // (TODO: actually a bit more than that but SURELY when it's less than two bytes, the + // program panics) rLength := bigEndianToInt(rLengthB) + if rLength < 2 { + continue + } + rMessage, err := readExactly(conn, rLength) if err != nil { zap.L().Debug(