From 3a399b056ed9b63a1ab6f1d9c9edb91d52be6bde Mon Sep 17 00:00:00 2001 From: Bora Alper Date: Sun, 5 Nov 2017 01:47:40 +0000 Subject: [PATCH] fixed a bug that occurs when rLength is smaller than two (in fetcher) --- magneticod/bittorrent/operations.go | 8 ++++++++ 1 file changed, 8 insertions(+) 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(