Mirror the mdata_used protection pattern from php_pcre_replace_func_impl
in php_pcre_match_impl, php_pcre_replace_impl, php_pcre_split_impl,
and php_pcre_grep_impl.
close GH-21291
Newer PCRE2 rejects \K in lookarounds at compile time, so the
negative-length match code path can no longer be triggered from
userland PHP. The PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK flag that would
re-enable it is only settable via the C compile context API.
Fix pcre2_code leak when pcre2_pattern_info() fails after a successful
pcre2_compile(), and fix match_sets/match_data/marks leak when
offsets[1] < offsets[0] in php_pcre_match_impl().
close GH-21298
When a PCRE execution error occurs (e.g. malformed UTF-8 with /u
modifier), preg_grep() was returning a partial result array containing
only the entries processed before the error. All other preg_* functions
return false on execution errors.
After the match loop, check PCRE_G(error_code) and if an error
occurred, destroy the partial array and return false instead.
Fixes GH-11936
In the latest version of libpcre2, the offsets appearing in some
"compilation failed" warnings have increased by one, as a result of
https://github.com/PCRE2Project/pcre2/pull/756
This is causing spurious test failures, so in this commit we replace
the hard-coded offsets by a regex that matches both values.
Gentoo-bug: https://bugs.gentoo.org/965018
Closes GH-20397
The pcre2 library still needs HAVE_MEMMOVE defined to use the system
(C99 standard) memmove() function, otherwise emulation is used. On
Windows, this is already enabled.
* ext/pcre: Refactor php_pcre_replace_func_impl() to not rely on an FCI
* ext/pcre: Refactor populate_subpat_array() to take subject as a HashTable*
This makes the assumption the zval is always an array explicit
* ext/pcre: Refactor php_pcre_replace_func_impl()
We don't need the FCI any more, and we always have the subject as a zend_string.
* ext/pcre: Refactor php_pcre_replace_func()
We don't need the FCI any more
* ext/pcre: Refactor php_replace_in_subject_func()
We don't need the FCI any more
Make the Hashtable param const
Throw exception on non string entries
* ext/pcre: Refactor preg_replace_func_impl()
We don't need the FCI anymore
Make the Hashtable params const
Rename function to indicate it is a PHP pcre function
* ext/pcre: Add trampoline tests for preg_replace_callback(_array)()
* ext/pcre: Handle trampolines properly for preg_replace_callback(_array)()
* Revert FCI passing removal
Because the subpattern names are persistent, and the fact that the
symbol table destruction is skipped when using fast_shutdown,
this means the refcounts will not be updated for the destruction of
the arrays that hold the subpattern name keys.
To solve this, detect this situation and duplicate the strings.
Closes GH-17132.
libpcre2 can return the special value -1 for a non-match.
In this case we get pointer overflow, although it doesn't matter in
practice because the pointer will be in bounds and the copy length will
be 0. Still, we should fix the UBSAN warning.
Closes GH-16205.