mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-08-10 21:30:59 +00:00
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:
@@ -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 }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user