iOS: Get the length from the generator

This fixes reading over the buffer if it is not zero terminated.
Fortunately, this was almost always the case by pure luck.