Skip to content

Fix multi-byte UTF-8 split across chunk buffers in LineReader. - #237

Open
grrrrrrrrr wants to merge 1 commit into
google:masterfrom
grrrrrrrrr:fix-io-read-line-lossy-utf8
Open

Fix multi-byte UTF-8 split across chunk buffers in LineReader.#237
grrrrrrrrr wants to merge 1 commit into
google:masterfrom
grrrrrrrrr:fix-io-read-line-lossy-utf8

Conversation

@grrrrrrrrr

Copy link
Copy Markdown
Collaborator

When a line spanned across multiple 8 KB buffer chunks,
read_line_lossy converted each chunk to a String independently via
String::from_utf8_lossy. If a multi-byte UTF-8 code point (e.g. 3-byte
or 4-byte character) straddled the 8 KB chunk boundary, the partial bytes
at the end of the first chunk and beginning of the next chunk were
treated as invalid UTF-8 and replaced with U+FFFD ().

This change buffers raw bytes across chunk refills for multi-chunk
lines, applying from_utf8_lossy once to the complete line byte slice.

When a line spanned across multiple 8 KB buffer chunks,
`read_line_lossy` converted each chunk to a `String` independently via
`String::from_utf8_lossy`. If a multi-byte UTF-8 code point (e.g. 3-byte
or 4-byte character) straddled the 8 KB chunk boundary, the partial bytes
at the end of the first chunk and beginning of the next chunk were
treated as invalid UTF-8 and replaced with `U+FFFD` ().

This change buffers raw bytes across chunk refills for multi-chunk
lines, applying `from_utf8_lossy` once to the complete line byte slice.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant