Update tail_frame.length in readData

When reading data from the buffer, this value was not updated. Depending
on the timing, this could cause non-date bytes to be interpreted as data
(and, since this could cause escape bytes to be missed, subsequently
could cause data to be dropped). It seems this did not often occur,
because most often data was not read through the buffer but directly.
Fix control flow in getFrameHeader

Before, it would not check the cid passed if there was already a frame
loaded. Furthermore, it would not check the cid of the frame jus loaded,
but of the previous frame.