actix/actix-web · error · io::Error

Invalid chunk size linear white space

Error message

Invalid chunk size linear white space

What it means

io::Error(InvalidInput, "Invalid chunk size linear white space") (chunked.rs:95-98) is returned by ChunkedState::read_size_lws when, after the chunk size and its optional linear whitespace, a character other than ';', CR, or more LWS appears. RFC 7230 allows only LWS, an extension delimiter ';', or CRLF after the size token.

Source

Thrown at actix-http/src/h1/chunked.rs:95

                Poll::Ready(Ok(ChunkedState::Size))
            }
            None => {
                debug!("chunk size would overflow u64");
                Poll::Ready(Err(io::Error::new(
                    io::ErrorKind::InvalidInput,
                    "Invalid chunk size line: Size is too big",
                )))
            }
        }
    }

    fn read_size_lws(rdr: &mut BytesMut) -> Poll<Result<ChunkedState, io::Error>> {
        match byte!(rdr) {
            // LWS can follow the chunk size, but no more digits can come
            b'\t' | b' ' => Poll::Ready(Ok(ChunkedState::SizeLws)),
            b';' => Poll::Ready(Ok(ChunkedState::Extension)),
            b'\r' => Poll::Ready(Ok(ChunkedState::SizeLf)),
            _ => Poll::Ready(Err(io::Error::new(
                io::ErrorKind::InvalidInput,
                "Invalid chunk size linear white space",
            ))),
        }
    }
    fn read_extension(rdr: &mut BytesMut) -> Poll<Result<ChunkedState, io::Error>> {
        match byte!(rdr) {
            b'\r' => Poll::Ready(Ok(ChunkedState::SizeLf)),
            // strictly 0x20 (space) should be disallowed but we don't parse quoted strings here
            0x00..=0x08 | 0x0a..=0x1f | 0x7f => Poll::Ready(Err(io::Error::new(
                io::ErrorKind::InvalidInput,
                "Invalid character in chunk extension",
            ))),
            _ => Poll::Ready(Ok(ChunkedState::Extension)), // no supported extensions
        }
    }
    fn read_size_lf(rdr: &mut BytesMut, size: u64) -> Poll<Result<ChunkedState, io::Error>> {
        match byte!(rdr) {

View on GitHub (pinned to 937960ca67)

Solutions

  1. Ensure the chunk size line is exactly '<hex> [;ext] CRLF'.
  2. Prefer Content-Length when the body size is known.
  3. Inspect the raw stream to find the stray character.

Example fix

// before
b"4 X\r\ndata\r\n0\r\n\r\n"

// after
b"4\r\ndata\r\n0\r\n\r\n"
Defensive patterns

Strategy: try-catch

Try / catch

// Same InvalidInput PayloadError handling as other chunked framing errors.
use actix_http::error::PayloadError;
if let Some(Err(PayloadError::Io(e))) = payload.next().await {
    if e.kind() == io::ErrorKind::InvalidInput {
        return HttpResponse::BadRequest().finish();
    }
}

Prevention

When it happens

Trigger: A chunked body has a size line like '4 X\r\n' — a stray non-LWS character after the hex size. read_size transitions to SizeLws on a space, then read_size_lws sees 'X' and errors.

Common situations: Hand-rolled chunk encoder inserting extra tokens, or a proxy injecting garbage after the size.

Related errors


AI-assisted analysis of actix/actix-web@937960ca67 (2026-08-06). Data as JSON: /data/errors/792c57f9a91e4e3a.json. Report an issue: GitHub.