-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
I believe I have discovered a conflict between the receiveBytes implementation which uses the FIFOBuffer and the internal implementation of the FIFOBuffer itself. The FIFOBuffer tracks data inside of a regular buffer, and the start of that data is not always located at the start of its own internal buffer. Functions such as write() will move this data if the amount written would place itself beyond the end of the internal buffer's storage.
I was accessing the FIFOBuffer's contents using operator[] when I encountered an assertion by the internal buffer stating that I was attempting to access an index which exceeded it's maximum allocated size. (I had the FIFOBuffer configured for 1024 bytes, so I expect the internal buffer matched that). I was reading from the FIFOBuffer at an index lower than the FIFOBuffer.used() function indicated. Upon debugging with GDB I found that _begin inside the FIFOBuffer was set to 60 for example, while _used was set to 1024.
Upon further inspection, I'm thinking that the issue might arise from StreamSocket.cpp line 140: 140 int ret = impl()->receiveBytes(fifoBuf.next(), (int)fifoBuf.available());
(gdb) next
141 if (ret > 0) fifoBuf.advance(ret);
Since FIFOBuffer.next() takes no precaution to shift the memory segment to the beginning of its allocation, I think the socket implementation is writing past its boundary and causing my issue. I also think this issue might be two-fold since the advance() function allows you to increase the _used variable beyond the internal buffer's length since it does not shift the data or the _begin variable either.
I've been wrong before, but hopefully this helps.