> ...the strings gets a little garbled on the end...
The length *includes* the header length. You are likely reading over theend of the string? Or you are expecting it to be null terminated, perTom Lane's comment.
- Thomas