-
Notifications
You must be signed in to change notification settings - Fork 136
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 gets out of sync when header/size/mask not received contiguously (IDFGH-13951) #679
Comments
Thanks for reporting this problem and proposing the fix!
static int esp_transport_read_exact_size(transport_ws_t *ws, char *buffer, int requested_len, int timeout_ms)
{
int total_read = 0;
int len = requested_len;
while (len > 0) {
int bytes_read = esp_transport_read_internal(ws, buffer, len, timeout_ms);
if (bytes_read < 0) {
return bytes_read; // Return error from the underlying read
}
if (bytes_read == 0) {
// If we read 0 bytes, we return an error, since reading exact number of bytes resulted in a timeout operation
ESP_LOGW(TAG, "Requested to read %d, actually read %d bytes", requested_len, total_read);
return -1;
}
// Update buffer and remaining length
buffer += bytes_read;
len -= bytes_read;
total_read += bytes_read;
ESP_LOGV(TAG, "Read fragment of %d bytes", bytes_read);
}
return total_read;
} Here's the updated test: |
Thanks @david-cermak , those updates look good to me, I'll integrate them and update my patch. I was a little confused about where this bug lived - I had confused ESP-IDF's transport_ws.c and ESP-Protocol's esp_websocket_client in this repo. If so, I'm sorry about that, please let me know if we need to do anything to clean up the tickets/pulls. |
@david-cermak , that's a cool use of a unit-test for this! I've got your changes integrated. In the last day or two our data provider updated their data, and we can no longer reproduce on live data. |
Answers checklist.
General issue report
Moving from espressif/esp-idf#14704 to here.
Under at least the following different cases, the ESP websocket parser gets out of sync with the byte stream, causing it to parse payload as headers.
A rough prototype fix is here: espressif/esp-idf#14706
The text was updated successfully, but these errors were encountered: