{"record":{"id":"2af93991c39f3069","repo":"larksuite/cli","slug":"invalid-content-range-end-d-is-outside-total-d","errorCode":null,"errorMessage":"invalid content range: end %d is outside total %d","messagePattern":"invalid content range: end (.+?) is outside total (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"extension/download/download.go","lineNumber":714,"sourceCode":"\tend, err := strconv.ParseInt(bounds[1], 10, 64)\n\tif err != nil {\n\t\treturn contentRange{}, fmt.Errorf(\"parse range end: %w\", err)\n\t}\n\ttotal, err := strconv.ParseInt(parts[1], 10, 64)\n\tif err != nil {\n\t\treturn contentRange{}, fmt.Errorf(\"parse total size: %w\", err)\n\t}\n\tif total <= 0 {\n\t\treturn contentRange{}, fmt.Errorf(\"invalid total size: %d\", total)\n\t}\n\tif start < 0 || end < 0 {\n\t\treturn contentRange{}, fmt.Errorf(\"invalid negative content range: %d-%d\", start, end)\n\t}\n\tif start > end {\n\t\treturn contentRange{}, fmt.Errorf(\"invalid content range: start %d is after end %d\", start, end)\n\t}\n\tif end >= total {\n\t\treturn contentRange{}, fmt.Errorf(\"invalid content range: end %d is outside total %d\", end, total)\n\t}\n\treturn contentRange{start: start, end: end, total: total}, nil\n}\n\n// strongETag returns a validator suitable for If-Range.\nfunc strongETag(header http.Header) (string, bool) {\n\tvalues := header.Values(\"ETag\")\n\tif len(values) != 1 {\n\t\treturn \"\", false\n\t}\n\ttag := strings.TrimSpace(values[0])\n\tif len(tag) < 2 || tag[0] != '\"' || tag[len(tag)-1] != '\"' {\n\t\treturn \"\", false\n\t}\n\tfor i := 1; i < len(tag)-1; i++ {\n\t\tif c := tag[i]; c != 0x21 && !(c >= 0x23 && c <= 0x7E) && c < 0x80 {\n\t\t\treturn \"\", false\n\t\t}","sourceCodeStart":696,"sourceCodeEnd":732,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/extension/download/download.go#L696-L732","documentation":"parseContentRange validates a Content-Range header parsed from a partial-download response in extension/download. The total length is exclusive-bound: a valid range end index must be < total. This error means the header advertises an end byte at or beyond the declared total size, which cannot describe a real byte range.","triggerScenarios":"A server (or proxy) returns a Content-Range header whose end value equals or exceeds the total length, e.g. 'bytes 0-1024/1024' instead of 'bytes 0-1023/1024', and openPartial/openNext feed it to parseContentRange.","commonSituations":"Broken or non-compliant HTTP servers/CDNs behind a proxy; unit tests with hand-written Content-Range strings; mis-parsed totals when a server reports Content-Length different from the range total.","solutions":["Check the server's Content-Range header for off-by-one values; end must be lastByteIndex, not byteCount","Verify the total in the header matches the resource's actual Content-Length","Correct test fixtures/mocks that fabricate invalid range headers","If you control the server, fix the range construction to use end = start + len - 1"],"exampleFix":"// before (invalid: end 1024 outside total 1024)\nContent-Range: bytes 0-1024/1024\n// after\nContent-Range: bytes 0-1023/1024","handlingStrategy":"validation","validationCode":"func validContentRange(hdr string) bool {\n  var s, e, t int64\n  if _, err := fmt.Sscanf(hdr, \"bytes %d-%d/%d\", &s, &e, &t); err != nil { return false }\n  return s <= e && e < t\n}","typeGuard":"func isPartialRange(r contentRange, total int64) bool { return r.end < total && r.start <= r.end }","tryCatchPattern":null,"preventionTips":["Assert test server Content-Range strings with end = total-1","Use httptest fixtures copied from real responses","Log raw headers on download failure","Pin to compliant proxies/CDNs when resuming downloads"],"tags":["http","download","content-range","validation"],"backgroundTag":"invalid-content-range-header","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}