#4276·actix-web

ws: 64-bit frame length MSB/32-bit truncation and fragmented text UTF-8 validation

Author: Sruhvx-jpgCreated Sep 27, 2026Updated Sep 27, 2026

Summary

During an AI-assisted systems audit of actix-http/src/ws/, memory safety and integer truncation edge cases were identified in 64-bit payload length parsing and fragmented text frame validation.


1. 64-Bit Payload Length MSB & 32-Bit Integer Truncation (RFC 6455 §5.2)

  • Location: actix-http/src/ws/frame.rs:77-83
  • Current Implementation:
    rust
    } else if len == 127 {
        if chunk_len < 10 {
            return Ok(None);
        }
        let len = u64::from_be_bytes(TryFrom::try_from(&src[idx..idx + 8]).unwrap());
        idx += 8;
        len as usize
    }
  • Issues:
    1. Missing MSB Enforcement: RFC 6455 §5.2 requires:

      "the most significant bit MUST be 0. (The payload length is an unsigned 63-bit integer.)" Frames with MSB set (len & (1 << 63) != 0) are not rejected with a protocol error.

    2. 32-bit Truncation: On 32-bit architectures (e.g., wasm32, 32-bit ARM/x86), len as usize silently truncates higher 32 bits. An incoming length like 0x1_0000_0004 truncates to 4, causing the parser to advance into mid-frame payload bytes and corrupting stream synchronization.
    3. Mitigation: Verify len & (1 << 63) == 0 and use usize::try_from(len).map_err(|_| ProtocolError::Overflow) instead of bare casting.

2. Streaming UTF-8 Boundary Bypass on Fragmented Text Frames (RFC 6455 §5.6 & §8.1)

  • Location: actix-http/src/ws/codec.rs:59-64 & actix-web-actors/src/ws.rs:801
  • Description:
    • Codec::decode emits continuation items as unvalidated Bytes (Item::FirstText, Item::Continue, Item::Last).
    • RFC 6455 §5.6 / §8.1 mandates:

      "When a text message is fragmented, the entire payload across all fragments MUST be valid UTF-8. If an endpoint receives a text message containing invalid UTF-8 data, the endpoint MUST Fail the WebSocket Connection."

    • Because intermediate continuation chunks are surfaced directly without a streaming UTF-8 state machine, multi-byte UTF-8 sequences split across frame boundaries bypass validation unless manually reconstructed downstream.

Note: This issue was identified via an AI-assisted systems audit suite.