{"id":"bea08c039da5f916","repo":"actix/actix-web","slug":"invalid-chunk-end-lf","errorCode":null,"errorMessage":"Invalid chunk end LF","messagePattern":"Invalid chunk end LF","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"actix-http/src/h1/chunked.rs","lineNumber":181,"sourceCode":"            _ => Poll::Ready(Err(io::Error::new(\n                io::ErrorKind::InvalidInput,\n                \"Invalid chunk body LF\",\n            ))),\n        }\n    }\n    fn read_end_cr(rdr: &mut BytesMut) -> Poll<Result<ChunkedState, io::Error>> {\n        match byte!(rdr) {\n            b'\\r' => Poll::Ready(Ok(ChunkedState::EndLf)),\n            _ => Poll::Ready(Err(io::Error::new(\n                io::ErrorKind::InvalidInput,\n                \"Invalid chunk end CR\",\n            ))),\n        }\n    }\n    fn read_end_lf(rdr: &mut BytesMut) -> Poll<Result<ChunkedState, io::Error>> {\n        match byte!(rdr) {\n            b'\\n' => Poll::Ready(Ok(ChunkedState::End)),\n            _ => Poll::Ready(Err(io::Error::new(\n                io::ErrorKind::InvalidInput,\n                \"Invalid chunk end LF\",\n            ))),\n        }\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use actix_codec::Decoder as _;\n    use bytes::{Bytes, BytesMut};\n    use http::Method;\n\n    use crate::{\n        error::ParseError,\n        h1::decoder::{MessageDecoder, PayloadItem},\n        HttpMessage as _, Request,\n    };","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/actix/actix-web/blob/937960ca67f20e14ffe2a075bf6d4593502be12c/actix-http/src/h1/chunked.rs#L163-L199","documentation":"io::Error(InvalidInput, \"Invalid chunk end LF\") (chunked.rs:181-184) is returned by read_end_lf when, after the final CR of the chunked trailer, the next byte is not an LF. This is the last byte of the chunked message; anything other than '\\n' means the trailer CRLF is broken.","triggerScenarios":"The chunked stream's final CRLF is corrupted, e.g. '0\\r\\n\\rX' — read_end_cr consumed the CR and read_end_lf sees 'X' instead of '\\n'.","commonSituations":"A truncated or corrupt trailer from a buggy encoder or proxy; connection closed mid-trailer.","solutions":["Ensure the message terminates with '0\\r\\n\\r\\n'.","Confirm the peer flushes the full trailer before closing the socket.","Capture the final bytes of the stream to locate the corruption."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Corrupt final LF -> incomplete/malformed body.\nuse actix_http::error::PayloadError;\nif matches!(payload.next().await, Some(Err(PayloadError::Io(e))) if e.kind() == io::ErrorKind::InvalidInput) {\n    return HttpResponse::BadRequest().finish();\n}","preventionTips":["Always close chunked streams with the full '0\\r\\n\\r\\n' trailer.","Ensure the peer flushes the entire trailer before connection close.","Capture the final bytes to locate corruption."],"tags":["http","transfer-encoding","chunked","actix-http","protocol"],"analyzedSha":"937960ca67f20e14ffe2a075bf6d4593502be12c","analyzedAt":"2026-08-06T01:15:46.978Z","schemaVersion":2}