bug69864.phpt 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. --TEST--
  2. Bug #69864 (Segfault in preg_replace_callback)
  3. --SKIPIF--
  4. <?php
  5. if (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. const PREG_CACHE_SIZE = 4096; // this has to be >= the resp. constant in php_pcre.c
  11. var_dump(preg_replace_callback('/a/', function($m) {
  12. for ($i = 0; $i < PREG_CACHE_SIZE; $i++) {
  13. preg_match('/foo' . $i . 'bar/', '???foo' . $i . 'bar???');
  14. }
  15. return 'b';
  16. }, 'aa'));
  17. var_dump(preg_replace_callback('/a/', function($m) {
  18. for ($i = 0; $i < PREG_CACHE_SIZE; $i++) {
  19. preg_replace('/foo' . $i . 'bar/', 'baz', '???foo' . $i . 'bar???');
  20. }
  21. return 'b';
  22. }, 'aa'));
  23. var_dump(preg_replace_callback('/a/', function($m) {
  24. for ($i = 0; $i < PREG_CACHE_SIZE; $i++) {
  25. preg_split('/foo' . $i . 'bar/', '???foo' . $i . 'bar???');
  26. }
  27. return 'b';
  28. }, 'aa'));
  29. var_dump(preg_replace_callback('/a/', function($m) {
  30. for ($i = 0; $i < PREG_CACHE_SIZE; $i++) {
  31. preg_grep('/foo' . $i . 'bar/', ['???foo' . $i . 'bar???']);
  32. }
  33. return 'b';
  34. }, 'aa'));
  35. ?>
  36. --EXPECT--
  37. string(2) "bb"
  38. string(2) "bb"
  39. string(2) "bb"
  40. string(2) "bb"