You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SimpleStreamReader cannot read multibyte characters on buffer boundaryΒ #2353
When reading character by character using UTF-8, SimpleStreamReader returns -1 (EOF) when it encounters an emoticon. The problem exists even when reading a lot of characters at once but is harder to reproduce (the four bytes of the emoticon must get misaligned with the buffer).
changed the title [-]SimpleStreamReader cannot read emoticons[/-][+]SimpleStreamReader cannot read multibyte characters on buffer boundary[/+]on Jun 30, 2025
I updated it so that when in this condition (a surrogate pair is straddling the buffer, and the requested len is not enough to read both characters), returns read length of zero. And handle that in the CharacterReader.
This saves having to track the last emitted high/low surrogate etc.
Note that reads of length 1 then may return 0 characters, and that r.read() is not implemented and won't work for surrogates correctly.
Activity
gbrdead commentedon Jun 29, 2025
input.txt
The following code:
does not create the same output as the input. I cannot simplify the example for the moment.
[-]SimpleStreamReader cannot read emoticons[/-][+]SimpleStreamReader cannot read multibyte characters on buffer boundary[/+]jhy commentedon Jun 30, 2025
Good find, thanks!
I updated it so that when in this condition (a surrogate pair is straddling the buffer, and the requested len is not enough to read both characters), returns read length of zero. And handle that in the CharacterReader.
This saves having to track the last emitted high/low surrogate etc.
Note that reads of length 1 then may return 0 characters, and that
r.read()is not implemented and won't work for surrogates correctly.If a surrogate is on the buffer boundary, break buffering
jhy commentedon Jul 4, 2025
@gbrdead can you validate this?
gbrdead commentedon Jul 5, 2025
Yes, it works for all the example data I have.