Skip to content

Commit acd667d

Browse files
committed
Add regression test demonstrating rehash protection during warning
1 parent 4a7ee3d commit acd667d

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
GH-20482: ZEND_ASSIGN_DIM survives a hash table rehash forced by the output handler during the undefined-variable warning
3+
--FILE--
4+
<?php
5+
$a = ['existing' => 0];
6+
7+
ob_start(function () use (&$a) {
8+
// Force several rehashes by adding many keys; the previously-allocated
9+
// bucket for $a['target'] (if it had been pre-fetched) would now point
10+
// into freed/relocated memory.
11+
for ($i = 0; $i < 64; $i++) {
12+
$a["k$i"] = $i;
13+
}
14+
return '';
15+
}, 1);
16+
17+
// Triggers "Undefined variable" -> output handler -> rehash. Without the
18+
// fix the previously-fetched bucket pointer would be stale; with the fix
19+
// variable_ptr is fetched fresh after the warning.
20+
$a['target'] = $undef;
21+
22+
ob_end_clean();
23+
var_dump($a['target'], count($a));
24+
echo "ok\n";
25+
?>
26+
--EXPECT--
27+
NULL
28+
int(66)
29+
ok

0 commit comments

Comments
 (0)