> The length header is important because the image itself may contain unused pixels at the end. If there's no length value, there's no way to know where the real payload stops.
Not really, can’t you just pad with 0 bytes and stop reading when you encounter one that’s not part of the current Unicode codepoint?
Zero bytes won't ever be part of a multi-byte character in UTF-8. They simply represent code point 0 (which is valid, but wouldn't appear in normal text) by themselves.
Ah even better so you can just use null terminated strings