-
Notifications
You must be signed in to change notification settings - Fork 8k
Expand file tree
/
Copy pathconcurrent_deletion.phpt
More file actions
46 lines (40 loc) · 981 Bytes
/
concurrent_deletion.phpt
File metadata and controls
46 lines (40 loc) · 981 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
--TEST--
SplObjectStorage: Concurrent deletion during iteration
--CREDITS--
cnitlrt
--FILE--
<?php
class EvilStorage extends SplObjectStorage {
public function getHash($obj): string {
global $victim;
static $counter = 0;
if ($counter++ < 1024*2) {
// Re-entrant mutation during removeAllExcept iteration
for ($i = 0; $i < 5; $i++) {
$victim[new stdClass()] = null;
}
}
return spl_object_hash($obj);
}
}
$victim = new SplObjectStorage();
$other = new EvilStorage();
for ($i = 0; $i < 1024; $i++) {
$o = new stdClass();
$victim[$o] = null;
$other[$o] = null;
}
var_dump($victim->removeAllExcept($other));
unset($victim, $other);
$victim = new SplObjectStorage();
$other = new EvilStorage();
for ($i = 0; $i < 1024; $i++) {
$o = new stdClass();
$victim[$o] = null;
$other[$o] = null;
}
var_dump($other->addAll($victim));
?>
--EXPECTF--
int(%d)
int(1024)