From f61085c7859f36a78391e32d302b0c6cd3fbb0db Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Thu, 29 Dec 2022 19:41:09 +1100 Subject: [PATCH] Avoid panic in AnnounceEvent.String --- tracker/udp/announce.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tracker/udp/announce.go b/tracker/udp/announce.go index 59b6c6cf..b5c9f8ff 100644 --- a/tracker/udp/announce.go +++ b/tracker/udp/announce.go @@ -38,7 +38,12 @@ func (me *AnnounceEvent) UnmarshalText(text []byte) error { var announceEventStrings = []string{"", "completed", "started", "stopped"} func (e AnnounceEvent) String() string { - // See BEP 3, "event", and https://github.com/anacrolix/torrent/issues/416#issuecomment-751427001. + // See BEP 3, "event", and + // https://github.com/anacrolix/torrent/issues/416#issuecomment-751427001. Return a safe default + // in case event values are not sanitized. + if e < 0 || int(e) >= len(announceEventStrings) { + return "" + } return announceEventStrings[e] } -- 2.48.1