nori0428/mod_websocket — Issue #17: read buffer length is wrong
Author: nori0428
Created: 2011-11-18 03:20:42+00:00
State: open

reported via email.

--- copied ---
Hello,

I'm not sure if this is a bug or not, but thought I would report it as it was problematic for me.

I have been using IETF hybi-00 with iOS & Safari (iPhone, iPad, Safari browser). Up until Chrome 14, chrome also worked. I recompiled and deployed on different servers the hybi-08 version to talk to chrome, but it did not work for me in some instances. I sent a lot of data through the websocket, usually bursts of 200k-250k which are read by the backend socket and then relayed to the front end client in this code:

mod_websocket.c
handler_t _handle_fdevent(server *srv, void *ctx, int revents) {
int b = 0;
handler_ctx *hctx = (handler_ctx *)ctx;
mod_websocket_frame_type_t frame_type;
char readbuf[UINT16_MAX + 1];
&n
bsp; ssize_t siz;

What I found was that (only for hybi-08, hybi-00 did not have this problem for some reason) if the packet was full, for me this is 65536 bytes, the Chrome string object given to websocket onmessage would have null bytes in it. This led to data corruption in the application layer. The following change solved the problem for me:

- char readbuf[UINT16_MAX + 1];
+ char readbuf[UINT16_MAX];

With readbuf 1 byte smaller, my problems went away. I did not debug further to find the exact cause of this, it's possible its a problem on my client code, but I expect its a bug in mod_websocket. Hopefully this is helpful. I would file a bug if I verified the problem further, but since it is working I am back to other projects.