Repository navigation
Conversation
\C was only forbidden with the u modifier, so the phpGH-21134 fix did not apply to patterns starting with (*UTF) or (*UTF8).
Girgias
left a comment
There was a problem hiding this comment.
This looks correct, and since PHP 8.4 requires libpcre 2.30 or above it means PCRE2_NEVER_BACKSLASH_C is always defined. However see comment as a way to prevent a recompile.
| && (all_options & PCRE2_UTF)) { | ||
| pcre2_code_free(re); | ||
| coptions |= PCRE2_NEVER_BACKSLASH_C; | ||
| re = pcre2_compile((PCRE2_SPTR)pattern, pattern_len, coptions, &errnumber, &erroffset, cctx); |
There was a problem hiding this comment.
Rather than recompiling you could check if it contains a \C by using PCRE2_INFO_HASBACKSLASHC
There was a problem hiding this comment.
Without recompiling we lose the offset, so the original message has been changed, but I don't think it's big concern. We can improve it on master.
Girgias
left a comment
There was a problem hiding this comment.
The improved error message can always just land in master if it's too much hassle
| if (key != regex) { | ||
| zend_string_release_ex(key, 0); | ||
| } | ||
| php_error_docref(NULL, E_WARNING, "Compilation failed: using \\C is incompatible with UTF-8 mode"); |
There was a problem hiding this comment.
We may want to improve the error message to mention the (*UTF) pattern verb?
There was a problem hiding this comment.
Sure, I prefer improve it more on master.
|
can this test be added eventually ? --TEST--
In-pattern (*UTF) validates the subject and advances by character like the /u modifier
--FILE--
<?php
var_dump(preg_match('/(*UTF)./', "\xff"));
echo preg_last_error_msg(), PHP_EOL;
var_dump(preg_split('/(*UTF)/', "\u{E4}b", -1, PREG_SPLIT_NO_EMPTY));
var_dump(preg_replace('/(*UTF)/', '-', "\u{E4}"));
var_dump(preg_match_all('/(*UTF)/', "\u{E4}"));
?>
--EXPECT--
bool(false)
Malformed UTF-8 characters, possibly incorrectly encoded
array(2) {
[0]=>
string(2) "ä"
[1]=>
string(1) "b"
}
string(4) "-ä-"
int(2) |
|
@devnexen this is another bug, that's not yet fixed. TBH, I reported it under security advisory and I didn't want to fix it in this PR. |
* PHP-8.4: (262 commits) Fix phpGH-25474: version_compare() numeric parts overflow long on Windows (php#25475) ext/session: prevent creation of fixed sid in php_session_rfc1867 (phpGH-22113) Forbid \C in patterns enabling UTF mode with (*UTF) (phpGH-25452) Fix phpGH-24743: var_export() ignores exception from lazy object init (php#24746) ext/snmp: Copy the context name in SNMP::setSecurity() Fix phpGH-25434: C14NFile() skips namespace relinking on success Fix uploaded files leak in request_parse_body() (php#25387) Fix phpGH-25094: NULL dereference in SOAP get_doc_function() with missing parts Pin Linux x86 CI to Ubuntu 24.04 (php#25416) Fix phpGH-25359: tracing JIT drops reference type of a named by-ref argument Fix AST export of by-reference property hooks (phpGH-25069) fix test when tmp-php.ini is used Fix stack overflow in filter_var() and filter_var_array() (php#25349) Align the Windows OPcache JIT buffer (php#25262) Fix phpGH-25311: Assertion ret == SUCCESS in array_map()/array_filter() after delayed out-of-memory Fix tracing JIT reading the int result of ++/-- on a reference as a double Fix error buffer cleanup in phar_open_parsed_phar() (php#25376) Fix phpGH-25306: Assertion status == LXB_STATUS_OK in dom_parse_selector when lexbor allocation fails Fix AST printing dropping readonly on promoted parameters (phpGH-25207) ext/gd: blame the points array when a polygon has too few points ...
\Cwas only forbidden with the u modifier, so the GH-21134 fix did not apply to patterns starting with(*UTF)or(*UTF8).