From 16be853e07071be24b158e9f7573ac1fc7372faf Mon Sep 17 00:00:00 2001 From: ap-pauloafonso Date: Sun, 29 Nov 2020 23:34:47 -0300 Subject: [PATCH] fix gzip reader with already flushed buffer --- ratiospoof/ratio-spoof.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/ratiospoof/ratio-spoof.go b/ratiospoof/ratio-spoof.go index 111c9c5..9346824 100644 --- a/ratiospoof/ratio-spoof.go +++ b/ratiospoof/ratio-spoof.go @@ -1,6 +1,7 @@ package ratiospoof import ( + "bytes" "compress/gzip" "crypto/sha1" "errors" @@ -413,23 +414,23 @@ func (R *ratioSPoofState) tryMakeRequest(query string) trackerResponse { } resp, err := R.httpClient.Do(req) if err == nil { - defer resp.Body.Close() if resp.StatusCode == http.StatusOK { - bytes, _ := ioutil.ReadAll(resp.Body) - mimeType := http.DetectContentType(bytes) + bytesR, _ := ioutil.ReadAll(resp.Body) + mimeType := http.DetectContentType(bytesR) if mimeType == "application/x-gzip" { - gzipReader, _ := gzip.NewReader(resp.Body) - defer gzipReader.Close() - bytes, _ = ioutil.ReadAll(gzipReader) + gzipReader, _ := gzip.NewReader(bytes.NewReader(bytesR)) + bytesR, _ = ioutil.ReadAll(gzipReader) + gzipReader.Close() } - R.lastTackerResponse = string(bytes) - decodedResp := beencode.Decode(bytes) + R.lastTackerResponse = string(bytesR) + decodedResp := beencode.Decode(bytesR) if idx != 0 { R.torrentInfo.trackerInfo.SwapFirst(idx) } ret := extractTrackerResponse(decodedResp) return ret } + resp.Body.Close() } } panic("Connection error with the tracker")