In fact, the problem was that the protocol has a compression defined. If the size of the next chains starts with 11xx xxxx, it means it's a pointer to a previous string, xx xxxx is the byte index of the stream.
I wasn't reading this, meaning that I was reading the 11xx xxxx has a length, giving me an huge length that was frequently out of range.