diff --git a/main.go b/main.go index 4cfb8ff..74d1078 100644 --- a/main.go +++ b/main.go @@ -20,6 +20,7 @@ import ( ) const TIMEOUT_NS time.Duration = time.Duration(60_000_000_000) +const MAX_FILE_SIZE int64 = 512 * 1024 var ( hosts tofu.KnownHosts @@ -158,23 +159,33 @@ func main() { if err != nil { log.Fatal(err) } + limitedBody := io.LimitedReader{ + R: resp.Body, + N: MAX_FILE_SIZE, + } defer resp.Body.Close() mime, _, _ := strings.Cut(resp.Meta, ";") if mime == "application/rss+xml" || mime == "application/rss" || mime == "application/atom+xml" || mime == "application/atom" || mime == "application/xml" || mime == "text/xml" { - out, err := io.ReadAll(resp.Body) + out, err := io.ReadAll(&limitedBody) if err != nil { log.Fatal(err) } + if limitedBody.N <= 0 { + log.Fatalf("up to %d bytes read from the body", MAX_FILE_SIZE) + } fmt.Print(string(out)) } else if mime == "text/gemini" { aw := AtomWriter{ Title: "", Items: nil, } - gemini.ParseLines(resp.Body, aw.Handle) + gemini.ParseLines(&limitedBody, aw.Handle) + if limitedBody.N <= 0 { + log.Fatalf("up to %d bytes read from the body", MAX_FILE_SIZE) + } sort.Sort(ByTime(aw.Items)) feed := Feed{ XMLNS: "http://www.w3.org/2005/Atom",