Skip to content

Conversation

@roxblnfk
Copy link
Member

@roxblnfk roxblnfk commented Nov 20, 2025

What was changed

Fixed WebSocket protocol support for large packets by correcting byte order encoding for 64-bit payload lengths:

  • Frame.php: Changed from pack('CJ') to pack('CNN') to encode 64-bit length as two 32-bit integers in network byte order (big-endian)
  • StreamReader.php: Changed from unpack('J') to unpack('N2') to decode 64-bit length in network byte order
  • FrameTest.php: Added comprehensive test suite covering all payload size ranges

Why?

The previous implementation used the 'J' format in pack()/unpack(), which uses machine-dependent byte order. This could cause failures on little-endian systems when handling WebSocket frames with payloads larger than 65535 bytes.

According to RFC 6455 Section 5.2, multibyte length quantities must be expressed in network byte order (big-endian). The fix ensures cross-platform compatibility by properly packing/unpacking 64-bit lengths as two 32-bit integers in network byte order.

Checklist

  • Closes Broken Websocket #197
  • Tested
    • Tested manually
    • Unit tests added (24 tests with 93 assertions covering small, medium, and large payloads)

Generated with ❤️ by Claude Code

… byte order

This commit improves WebSocket protocol support for large packets by fixing
the byte order encoding for 64-bit payload lengths according to RFC 6455.

Changes:
- Frame.php: Changed from pack('CJ') to pack('CNN') to encode 64-bit length
  as two 32-bit integers in network byte order (big-endian)
- StreamReader.php: Changed from unpack('J') to unpack('N2') to decode
  64-bit length in network byte order
- Added comprehensive test suite for different payload sizes (small <126,
  medium 126-65535, large 65536+ bytes)

The previous implementation used machine-dependent byte order ('J' format),
which could fail on little-endian systems. The new implementation correctly
uses network byte order as required by the WebSocket specification.

All tests pass: 24 tests with 93 assertions.
@github-actions github-actions bot added the tests Changes in the tests label Nov 20, 2025
@roxblnfk roxblnfk merged commit 24b7597 into master Nov 20, 2025
@roxblnfk roxblnfk deleted the claude/websocket-large-packets-018m1atQb2aXa9t5vZwGPMAC branch November 20, 2025 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Changes in the tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Broken Websocket

3 participants