Skip to content

Commit 73eace2

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: Fix GH-21731: Random\Engine\Xoshiro256StarStar::__unserialize() accepts all-zero state (#21732)
2 parents f90e532 + 1a428e5 commit 73eace2

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ PHP NEWS
3333
. Fix memory leak regression in openssl_pbkdf2(). (ndossche)
3434
. Fix a bunch of memory leaks and crashes on edge cases. (ndossche)
3535

36+
- Random:
37+
. Fixed bug GH-21731 (Random\Engine\Xoshiro256StarStar::__unserialize()
38+
accepts all-zero state). (iliaal)
39+
3640
- SPL:
3741
. Fixed bug GH-21499 (RecursiveArrayIterator getChildren UAF after parent
3842
free). (Girgias)

ext/random/engine_xoshiro256starstar.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ static bool unserialize(void *state, HashTable *data)
151151
}
152152
}
153153

154+
if (UNEXPECTED(s->state[0] == 0 && s->state[1] == 0 && s->state[2] == 0 && s->state[3] == 0)) {
155+
return false;
156+
}
157+
154158
return true;
155159
}
156160

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
GH-21731: Xoshiro256StarStar::__unserialize() must reject the all-zero state
3+
--FILE--
4+
<?php
5+
6+
try {
7+
var_dump(unserialize('O:32:"Random\Engine\Xoshiro256StarStar":2:{i:0;a:0:{}i:1;a:4:{i:0;s:16:"0000000000000000";i:1;s:16:"0000000000000000";i:2;s:16:"0000000000000000";i:3;s:16:"0000000000000000";}}'));
8+
} catch (\Exception $e) {
9+
echo $e->getMessage(), PHP_EOL;
10+
}
11+
12+
?>
13+
--EXPECT--
14+
Invalid serialization data for Random\Engine\Xoshiro256StarStar object

0 commit comments

Comments
 (0)