mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #5495] [MERGED] fix(sub): error on oversized external subscription instead of silent truncation #5903
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#5903
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/5495
Author: @n0ctal
Created: 6/22/2026
Status: ✅ Merged
Merged: 6/23/2026
Merged by: @MHSanaei
Base:
main← Head:pr-0015-bound-external-sub📝 Commits (2)
4057770fix(sub): error instead of silently truncating oversized subscription7443dc2Merge branch 'main' into pr-0015-bound-external-sub📊 Changes
2 files changed (+51 additions, -2 deletions)
View changed files
📝
internal/sub/external_subscription.go(+8 -2)➕
internal/sub/external_subscription_test.go(+43 -0)📄 Description
Summary
The external subscription fetcher capped the remote body with a plain
io.LimitReader(resp.Body, subscriptionMaxBytes), which silently truncates at the 2 MiB limit and decodes whatever prefix arrived. This switches to the established N+1 overflow-detection pattern and returns an error on oversize instead of truncating.Why
doFetchSubscriptionLinksaggregates a remote newline list of share links. When the body exceeds 2 MiB the old code returned a partial list — and the cut can land mid-link — so the client renders a complete-looking but actually truncated set of configs. Erroring is safer than silently serving a corrupted subset; the existing caller already falls back to the last cached value on error.Scope
internal/sub/external_subscription.go: readsubscriptionMaxBytes+1viaLimitReader; if the body exceeds the limit, return a newerrSubscriptionBodyTooLarge(same*subErrorstyle as the existingerrBadStatus).internal/sub/external_subscription_test.go(new): over-limit body returns the sentinel error and nil links; an exactly-at-limit body round-trips its link.Validation
gofmtclean (touched files),go vet ./internal/sub/,go build ./..., and the two new tests pass.Risk
Behavioral change: a legitimately >2 MiB subscription previously rendered truncated-partial and now errors, so the caller serves the last cached value (or nil) instead. The 2 MiB cap itself is unchanged. 2 MiB of newline-separated links is tens of thousands of entries, so exceeding it indicates a misbehaving or hostile provider far more than a real need. Single-file revert.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.