[php-src] PR #25769: Fix Dom\HTMLDocument::createFromFile() UTF-8 fast-path across >=3 reads
| From: | hohphu8 | Date: | Thu, 26 Nov 2026 04:21:53 +0000 |
| Subject: | [php-src] PR #25769: Fix Dom\HTMLDocument::createFromFile() UTF-8 fast-path across >=3 reads | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-41029@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/25769
Author: hohphu8
In
dom_decode_encode_fast_path() (ext/dom/html_document.c), when resuming
with decoding_encoding_ctx->decode.status == LXB_STATUS_CONTINUE, the return value
of lxb_encoding_decode_utf_8_single() is passed to
lxb_encoding_encode_utf_8_single() without checking for
LXB_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 as U+FFFD plus a
stray byte).
This PR returns early with *buf_ref_ref = buf_ref when the result is
LXB_ENCODING_DECODE_CONTINUE, leaving the decoder state as
LXB_STATUS_CONTINUE so the next chunk resumes the sequence. A sequence truncated at EOF
still becomes U+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.