chenhg5/cc-connect · error

wecom-ws: media larger than %d bytes

Error message

wecom-ws: media larger than %d bytes

What it means

downloadWeComWSMedia reads the body through an io.LimitReader capped at wecomWSMediaMaxBytes+1; if more bytes than the cap arrive, the download is rejected with this size-limit error instead of buffering an unbounded payload into memory. It is a deliberate DoS/memory guard on WeCom websocket media downloads.

Source

Thrown at platform/wecom/websocket_media.go:359

		return nil, "", err
	}
	client := &http.Client{Timeout: 90 * time.Second}
	resp, err := client.Do(req)
	if err != nil {
		return nil, "", err
	}
	defer resp.Body.Close()
	if resp.StatusCode < 200 || resp.StatusCode >= 300 {
		return nil, "", fmt.Errorf("wecom-ws: download HTTP %s", resp.Status)
	}
	fileName = parseContentDispositionFilename(resp.Header.Get("Content-Disposition"))
	lim := io.LimitReader(resp.Body, wecomWSMediaMaxBytes+1)
	raw, err := io.ReadAll(lim)
	if err != nil {
		return nil, "", err
	}
	if len(raw) > wecomWSMediaMaxBytes {
		return nil, "", fmt.Errorf("wecom-ws: media larger than %d bytes", wecomWSMediaMaxBytes)
	}
	if aesKey != "" {
		raw, err = wecomDecryptFile(raw, aesKey)
		if err != nil {
			return nil, "", err
		}
	}
	return raw, fileName, nil
}

// deliverWSMediaInbound downloads media and forwards one core.Message. Quoted media
// is downloaded first so attachment order mirrors the quoted-context prompt.
func (p *WSPlatform) deliverWSMediaInbound(body *wsMsgCallbackBody, sessionKey, chatName string, rctx wsReplyContext, current, quoted wsInboundParts, fromVoice bool) {
	ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
	defer cancel()

	var images []core.ImageAttachment
	var fileAtts []core.FileAttachment

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Raise wecomWSMediaMaxBytes if your deployment legitimately needs larger media (weigh memory use).
  2. Surface a user-facing message that the media exceeds the supported size limit instead of retrying.
  3. Check Content-Length before reading and reject oversized downloads early with a clear message.

Example fix

// before
const wecomWSMediaMaxBytes = 10 << 20 // 10MB, too small for videos
// after
const wecomWSMediaMaxBytes = 100 << 20 // 100MB
// and/or: if resp.ContentLength > wecomWSMediaMaxBytes { return nil, "", errMediaTooLarge }
Defensive patterns

Strategy: validation

Validate before calling

if resp.ContentLength > maxSupportedBytes {
    return fmt.Errorf("media too large: %d > %d", resp.ContentLength, maxSupportedBytes)
}

Try / catch

raw, err := downloadWeComWSMedia(url, key)
if err != nil && strings.Contains(err.Error(), "media larger than") {
    sendUserMessage(chatID, "File exceeds the supported size limit")
}

Prevention

When it happens

Trigger: The media URL serves a file whose size exceeds wecomWSMediaMaxBytes — e.g. a large video/document sent to the bot — and downloadWeComWSMedia is called on it.

Common situations: Users sending large videos or long files through WeCom; a misconfigured (too small) wecomWSMediaMaxBytes constant rejecting normal images; proxy concatenating responses.

Understand the failure class

Background: "File too large" / "file size exceeds limit" errors: why libraries cap file sizes and how to fix them — this error's family across 46 libraries.

Related errors


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