{"record":{"id":"0b93240b50d593a4","repo":"chenhg5/cc-connect","slug":"resource-too-large-content-length-d-exceeds-cap","errorCode":null,"errorMessage":"resource too large: Content-Length=%d exceeds cap %d","messagePattern":"resource too large: Content-Length=(.+?) exceeds cap (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"platform/feishu/resource_download.go","lineNumber":273,"sourceCode":"\treq, err := http.NewRequestWithContext(ctx, http.MethodGet, p.resourceURL(messageID, fileKey, resType), nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"build request: %w\", err)\n\t}\n\treq.Header.Set(\"Authorization\", \"Bearer \"+token)\n\n\tresp, err := p.resourceDownloadHTTP.Do(req)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"resource request: %w\", err)\n\t}\n\tdefer func() { _ = resp.Body.Close() }()\n\n\tif resp.StatusCode < 200 || resp.StatusCode >= 300 {\n\t\tbody, _ := io.ReadAll(io.LimitReader(resp.Body, 4*1024))\n\t\treturn nil, fmt.Errorf(\"resource API status=%d body=%q\", resp.StatusCode, strings.TrimSpace(string(body)))\n\t}\n\n\tif cl := resp.ContentLength; cl > p.resourceMaxBytes {\n\t\treturn nil, fmt.Errorf(\"resource too large: Content-Length=%d exceeds cap %d\", cl, p.resourceMaxBytes)\n\t}\n\n\t// LimitReader caps the body too in case the server lies about\n\t// Content-Length; we read up to cap+1 bytes to detect the lie.\n\tdata, err := io.ReadAll(io.LimitReader(resp.Body, p.resourceMaxBytes+1))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"read resource: %w\", err)\n\t}\n\tif int64(len(data)) > p.resourceMaxBytes {\n\t\treturn nil, fmt.Errorf(\"resource too large: body exceeds cap %d\", p.resourceMaxBytes)\n\t}\n\tslog.Debug(p.tag()+\": resource downloaded (single GET)\",\n\t\t\"file_key\", fileKey, \"type\", resType, \"size\", len(data))\n\treturn data, nil\n}\n\n// resourceRangeChunk fetches a single byte range and verifies the\n// Content-Range header agrees with what we asked for. Returns the bytes","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/feishu/resource_download.go#L255-L291","documentation":"During a single-GET download the response's Content-Length exceeds the platform's configured resourceMaxBytes cap, so the library refuses to download the file to protect memory. This is a deliberate guard against oversized resources, not a transport failure.","triggerScenarios":"resourceSingleGet receives a 2xx response whose resp.ContentLength is greater than p.resourceMaxBytes — i.e. the file being downloaded is larger than the configured maximum.","commonSituations":"User sends a very large file (video, archive) to the bot and the agent requests it as an attachment; resourceMaxBytes configured too low for the team's normal file sizes; resourceMaxBytes left at a conservative default.","solutions":["Raise resourceMaxBytes in the Feishu platform config to accommodate the file sizes you expect","Reject the download upstream: check the message's file size metadata against the cap before attempting download and inform the user the file is too large","Ensure the chunked path is used for large files — the single-GET path is only for small files/probe failures, so fix the size probe if it is incorrectly falling back","If downloads of large files are genuinely needed, stream to disk instead of enforcing an in-memory cap"],"exampleFix":"// before: config.toml\n[platforms.feishu]\nresource_max_bytes = 10485760  # 10 MB\n// after\n[platforms.feishu]\nresource_max_bytes = 104857600  # 100 MB","handlingStrategy":"validation","validationCode":"// check size from message metadata before download\nif fileSizeBytes > maxAllowedBytes {\n    return fmt.Errorf(\"file too large: %d bytes (max %d)\", fileSizeBytes, maxAllowedBytes)\n}","typeGuard":null,"tryCatchPattern":"data, err := p.resourceDownloadStream(ctx, token, msgID, fileKey, resType)\nif err != nil {\n    if strings.Contains(err.Error(), \"resource too large\") {\n        return nil, ErrFileTooLarge // surface a friendly user message\n    }\n    return err\n}","preventionTips":["Set resourceMaxBytes to cover the largest attachments your users send","Advertise file-size limits to users before they upload","Read the file size from message metadata and refuse oversized files early"],"tags":["limit","file-size","configuration","feishu"],"backgroundTag":"payload-too-large","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}