Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Websocket parser fails when header/size/mask not received contiguously. (IDFGH-13857) #14704

Open
3 tasks done
bryghtlabs-richard opened this issue Oct 10, 2024 · 2 comments · May be fixed by #14706
Open
3 tasks done
Assignees
Labels
Status: Opened Issue is new Type: Bug bugs in IDF

Comments

@bryghtlabs-richard
Copy link
Contributor

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

v5.1.2

Espressif SoC revision.

ESP32-S3

Operating System used.

Windows

How did you build your project?

Command line with idf.py

If you are using Windows, please specify command line type.

CMD

Development Kit.

Custom board with esp32s3-wroom-1

Power Supply used.

USB

What is the expected behavior?

I expect esp_transport_read_internal() to wait up to timeout_ms milliseconds to read data.

What is the actual behavior?

When reading a websocket header, and the buffer layer has 1B inside it, esp_transport_read_internal() returns 1B, and ws_read_header() does not check for this, so the stream becomes misaligned by 1B. Then WS parsing is corrupt and parser cannot be realigned.

Steps to reproduce.

  1. Decrease MTU to minimum
  2. Setup server to send random-length WS frames
  3. Hope that somehow we align on 1B buffer boundary
  4. add assert(rlen==header) to ws_read_header() after esp_transport_read_internal()

Debug Logs.

I (11887) SIOC: unhandled text msg:~

^This is because "~" is the next byte of the websocket header.

More Information.

No response

@bryghtlabs-richard bryghtlabs-richard added the Type: Bug bugs in IDF label Oct 10, 2024
@espressif-bot espressif-bot added the Status: Opened Issue is new label Oct 10, 2024
@github-actions github-actions bot changed the title Websocket parser fails when 1B in buffer. Websocket parser fails when 1B in buffer. (IDFGH-13857) Oct 10, 2024
@bryghtlabs-richard
Copy link
Contributor Author

Also fails when buffer has 0B, underlying transport read returns 1B due to packet boundaries.

@bryghtlabs-richard
Copy link
Contributor Author

Also fails when reading > 125B packet, and size sub-header fields are fragmented(either due to buffer or packet boundaries).

@bryghtlabs-richard bryghtlabs-richard changed the title Websocket parser fails when 1B in buffer. (IDFGH-13857) Websocket parser fails when header/size/mask not received contiguously. (IDFGH-13857) Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Opened Issue is new Type: Bug bugs in IDF
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants