chenhg5/cc-connect · error

%s: CDN body exceeds %d bytes

Error message

%s: CDN body exceeds %d bytes

What it means

The downloaded CDN body exceeds maxWeixinMediaBytes (detected via LimitReader of max+1), so the media file is larger than the platform is willing to buffer in memory. This is a hard size guard against oversized Weixin media, not a network error.

Source

Thrown at platform/weixin/cdn.go:143

func fetchCdnBytes(ctx context.Context, client *http.Client, fullURL, label string) ([]byte, error) {
	if client == nil {
		client = http.DefaultClient
	}
	req, err := http.NewRequestWithContext(ctx, http.MethodGet, fullURL, nil)
	if err != nil {
		return nil, fmt.Errorf("%s: new request: %w", label, err)
	}
	resp, err := client.Do(req)
	if err != nil {
		return nil, fmt.Errorf("%s: get: %w", label, err)
	}
	defer resp.Body.Close()
	body, err := io.ReadAll(io.LimitReader(resp.Body, maxWeixinMediaBytes+1))
	if err != nil {
		return nil, fmt.Errorf("%s: read: %w", label, err)
	}
	if len(body) > maxWeixinMediaBytes {
		return nil, fmt.Errorf("%s: CDN body exceeds %d bytes", label, maxWeixinMediaBytes)
	}
	if resp.StatusCode != http.StatusOK {
		return nil, fmt.Errorf("%s: CDN http %d: %s", label, resp.StatusCode, truncateForLog(body, 256))
	}
	return body, nil
}

func downloadAndDecryptCDN(ctx context.Context, client *http.Client, cdnBase, encParam, aesKeyBase64, label string) ([]byte, error) {
	key, err := parseAesKey(aesKeyBase64, label)
	if err != nil {
		return nil, err
	}
	u := buildCdnDownloadURL(encParam, cdnBase)
	enc, err := fetchCdnBytes(ctx, client, u, label)
	if err != nil {
		return nil, err
	}
	plain, err := decryptAESECB(enc, key)

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Skip the oversized attachment and inform the user instead of failing the whole message
  2. If larger files must be supported, raise maxWeixinMediaBytes or stream to disk rather than buffering in memory
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at platform/weixin/cdn.go:143 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/6f4506cc5e7b7884. Report an issue: GitHub.