Repository navigation
Conversation
In dom_decode_encode_fast_path(), resuming with LXB_STATUS_CONTINUE did not check for LXB_ENCODING_DECODE_CONTINUE,
passing the sentinel codepoint to lxb_encoding_encode_utf_8_single() and injecting U+FFFD when a multibyte UTF-8 character
spans three or more short reads.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In
dom_decode_encode_fast_path()(ext/dom/html_document.c), when resuming withdecoding_encoding_ctx->decode.status == LXB_STATUS_CONTINUE, the return value oflxb_encoding_decode_utf_8_single()is passed tolxb_encoding_encode_utf_8_single()without checking forLXB_ENCODING_DECODE_CONTINUE.When a 3- or 4-byte UTF-8 sequence spans three or more short reads, the "need more bytes" result is treated as an invalid codepoint and replaced with
U+FFFD, so valid input is corrupted (e.g.€split across three reads comes out asU+FFFDplus a stray byte).This PR returns early with
*buf_ref_ref = buf_refwhen the result isLXB_ENCODING_DECODE_CONTINUE, leaving the decoder state asLXB_STATUS_CONTINUEso the next chunk resumes the sequence. A sequence truncated at EOF still becomesU+FFFD(covered by the test).Adds
ext/dom/tests/modern/html/parser/HTMLDocument_createFromFile_utf8_multichunk.phpt, which uses a user stream wrapper that returns the bytes in separate chunks. It fails before the fix and passes after.Note: I found this through source inspection with an automated/LLM-assisted tool, then reproduced and verified it myself.