mirror of
https://github.com/apple/swift-nio
synced 2026-11-22 04:30:41 +00:00
RFC 6455 §5.2 specifies that when the payload length indicator byte is 127, the following 8 bytes hold a 64-bit unsigned integer and the most significant bit of that integer must be 0. The maximum legal value is therefore 0x7FFFFFFFFFFFFFFF, which equals Int.max on all 64-bit platforms Swift supports. WSParser.parseStep read the raw UInt64 and passed it directly to Int() without a bounds check. Swift's Int initializer performs a checked conversion and traps on overflow, so any remote peer that sends a single WebSocket frame with the MSB of the 8-byte length set will cause a fatal error in the receiving process. No authentication is required; the frame is processed before any application handler runs. The fix adds a guard that rejects the frame with NIOWebSocketError.invalidFrameLength before the conversion, which is the same error path used for frames that exceed maxFrameSize. The call site in decode() is updated to propagate the throw. A regression test covers the exact byte sequence that previously caused the fatal trap. Co-authored-by: g0w6y <g0w6y@users.noreply.github.com> Co-authored-by: Cory Benfield <lukasa@apple.com>