fix(sub): error instead of silently truncating oversized subscription (#5495)

The external subscription fetcher read the remote body with a plain
io.LimitReader, silently truncating at 2 MiB and decoding whatever
prefix arrived (possibly a half share link). Detect the overflow with
the established N+1 pattern and return an error so the caller serves the
last cached value instead of a corrupted partial list.

Co-authored-by: Sanaei <ho3ein.sanaei@gmail.com>
This commit is contained in:
n0ctal
2026-06-23 13:47:29 +05:00
committed by GitHub
parent dabd3f5d2b
commit 67344cae6f
2 changed files with 51 additions and 2 deletions
+8 -2
View File
@@ -78,14 +78,20 @@ func doFetchSubscriptionLinks(rawURL string) ([]string, error) {
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return nil, errBadStatus
}
body, err := io.ReadAll(io.LimitReader(resp.Body, subscriptionMaxBytes))
body, err := io.ReadAll(io.LimitReader(resp.Body, subscriptionMaxBytes+1))
if err != nil {
return nil, err
}
if len(body) > subscriptionMaxBytes {
return nil, errSubscriptionBodyTooLarge
}
return decodeSubscriptionBody(body), nil
}
var errBadStatus = &subError{"non-2xx subscription response"}
var (
errBadStatus = &subError{"non-2xx subscription response"}
errSubscriptionBodyTooLarge = &subError{"subscription response body exceeds size limit"}
)
type subError struct{ msg string }