xref: /PHP-7.2/ext/pcre/tests/bug69864.phpt (revision 3f72c77c)
1--TEST--
2Bug #69864 (Segfault in preg_replace_callback)
3--SKIPIF--
4<?php
5if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
6?>
7--FILE--
8<?php
9/* CAUTION: this test will most likely fail with valgrind until --smc-check=all is used. */
10
11const PREG_CACHE_SIZE = 4096; // this has to be >= the resp. constant in php_pcre.c
12
13var_dump(preg_replace_callback('/a/', function($m) {
14    for ($i = 0; $i < PREG_CACHE_SIZE; $i++) {
15        preg_match('/foo' . $i . 'bar/', '???foo' . $i . 'bar???');
16    }
17    return 'b';
18}, 'aa'));
19var_dump(preg_replace_callback('/a/', function($m) {
20    for ($i = 0; $i < PREG_CACHE_SIZE; $i++) {
21        preg_replace('/foo' . $i . 'bar/', 'baz', '???foo' . $i . 'bar???');
22    }
23    return 'b';
24}, 'aa'));
25var_dump(preg_replace_callback('/a/', function($m) {
26    for ($i = 0; $i < PREG_CACHE_SIZE; $i++) {
27        preg_split('/foo' . $i . 'bar/', '???foo' . $i . 'bar???');
28    }
29    return 'b';
30}, 'aa'));
31var_dump(preg_replace_callback('/a/', function($m) {
32    for ($i = 0; $i < PREG_CACHE_SIZE; $i++) {
33        preg_grep('/foo' . $i . 'bar/', ['???foo' . $i . 'bar???']);
34    }
35    return 'b';
36}, 'aa'));
37?>
38--EXPECT--
39string(2) "bb"
40string(2) "bb"
41string(2) "bb"
42string(2) "bb"
43