xref: /PHP-8.1/ext/opcache/tests/gh9164.phpt (revision bccda7eb)
1--TEST--
2Bug GH-9164: Segfault in zend_accel_class_hash_copy
3--EXTENSIONS--
4opcache
5pcntl
6--INI--
7opcache.enable_cli=1
8--FILE--
9<?php
10
11$incfile = __DIR__.'/gh9164.inc';
12
13// Generate enough classes so that the out of bound access will cause a crash
14// without relying on assertion
15$fd = fopen($incfile, 'w');
16fwrite($fd, "<?php\n");
17for ($i = 0; $i < 4096; $i++) {
18    fprintf($fd, "class FooBar%04d {}\n", $i);
19}
20fclose($fd);
21
22// Ensure cacheability
23touch($incfile, time() - 3600);
24
25$pid = pcntl_fork();
26if ($pid == 0) {
27    // Child: Declare classes to allocate CE cache slots.
28    require $incfile;
29} else if ($pid > 0) {
30    pcntl_wait($status);
31    // Ensure that file has been cached. If not, this is testing nothing anymore.
32    if (!isset(opcache_get_status()['scripts'][$incfile])) {
33        print "File not cached\n";
34    }
35    // Populates local cache
36    require $incfile;
37    var_dump(new FooBar4095);
38    unlink($incfile);
39} else {
40    echo "pcntl_fork() failed\n";
41}
42
43?>
44--EXPECTF--
45object(FooBar4095)#%d (0) {
46}
47