{"record":{"id":"7f819af335a97978","repo":"seanmonstar/warp","slug":"valid-contentrange","errorCode":null,"errorMessage":"valid ContentRange","messagePattern":"valid ContentRange","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"info","filePath":"src/filters/fs.rs","lineNumber":328,"sourceCode":"        let mut len = meta.len();\n        let modified = meta.modified().ok().map(LastModified::from);\n\n        let resp = match conditionals.check(modified) {\n            Cond::NoBody(resp) => resp,\n            Cond::WithBody(range) => {\n                bytes_range(range, len)\n                    .map(|(start, end)| {\n                        let sub_len = end - start;\n                        let buf_size = optimal_buf_size(&meta);\n                        let stream = file_stream(file, buf_size, (start, end));\n                        let body = Body::wrap_stream(stream);\n\n                        let mut resp = Response::new(body);\n\n                        if sub_len != len {\n                            *resp.status_mut() = StatusCode::PARTIAL_CONTENT;\n                            resp.headers_mut().typed_insert(\n                                ContentRange::bytes(start..end, len).expect(\"valid ContentRange\"),\n                            );\n\n                            len = sub_len;\n                        }\n\n                        let mime = mime_guess::from_path(path.as_ref()).first_or_octet_stream();\n\n                        resp.headers_mut().typed_insert(ContentLength(len));\n                        resp.headers_mut().typed_insert(ContentType::from(mime));\n                        resp.headers_mut().typed_insert(AcceptRanges::bytes());\n\n                        if let Some(last_modified) = modified {\n                            resp.headers_mut().typed_insert(last_modified);\n                        }\n\n                        resp\n                    })\n                    .unwrap_or_else(|BadRange| {","sourceCodeStart":310,"sourceCodeEnd":346,"githubUrl":"https://github.com/seanmonstar/warp/blob/ff34d7213ed55ec342304aa7ff6ac4b351da9e66/src/filters/fs.rs#L310-L346","documentation":"In the filesystem filter, when serving a byte sub-range the code builds an HTTP `ContentRange` header via `ContentRange::bytes(start..end, len).expect(\"valid ContentRange\")` (src/filters/fs.rs:328). The `http-range-header` crate returns an error (and warp panics) if the range is invalid: start >= end, range beyond/inconsistent with total length, or a range that cannot be represented. Given warp computes start/end/len from the actual file, this should be mathematically unreachable and is an internal invariant panic.","triggerScenarios":"A client sends a `Range` header and the computed sub-range (start..end) is inconsistent with the file length — theoretically only if range parsing bounds were violated. Practically unreachable through the public `warp::fs` API because warp validates ranges before slicing.","commonSituations":"Not normally hit by library users; could surface only if a proxy or client sends pathological Range headers that slip past validation, or with a modified/custom fs filter computing its own ranges.","solutions":["If you implement custom range logic, validate 0 <= start < end <= len before constructing `ContentRange::bytes(..)`","Use `ContentRange::bytes(..)` with checked/clamped bounds instead of `expect` in custom filters","Prefer the built-in `warp::fs::file`/`warp::fs::dir` which handle Range headers internally","If hit, inspect the client's raw `Range` header for malformed values like bytes=start-end with start>end"],"exampleFix":"// before\nContentRange::bytes(start..end, len).expect(\"valid ContentRange\"),\n// after\nassert!(start < end && end <= len, \"invalid range {}..{} for len {}\", start, end, len);\nContentRange::bytes(start..end, len).expect(\"valid ContentRange\"),","handlingStrategy":"try-catch","validationCode":"// before constructing a ContentRange in custom code:\nfn valid_range(start: u64, end: u64, len: u64) -> bool { start < end && end <= len }","typeGuard":null,"tryCatchPattern":"// warp's expect is internal; if you write custom range code:\nmatch http_range_header::ContentRange::bytes(start..end, len) {\n    Ok(cr) => resp.headers_mut().typed_insert(cr),\n    Err(_) => *resp.status_mut() = StatusCode::RANGE_NOT_SATISFIABLE,\n}","preventionTips":["Use the built-in warp::fs filters instead of hand-rolling range responses","Clamp and validate computed ranges against file length before header construction","Return 416 Range Not Satisfiable for malformed client Range headers"],"tags":["http","range-requests","panic","filesystem"],"backgroundTag":"internal-invariant-violation","analyzedSha":"ff34d7213ed55ec342304aa7ff6ac4b351da9e66","analyzedAt":"2026-09-09T16:57:46.316Z","contentChangedAt":"2026-09-09T16:57:46.316Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}