Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ PHP NEWS
- OpenSSL:
. Fix a bunch of memory leaks and crashes on edge cases. (ndossche)

- Random:
. Fixed bug GH-21731 (Random\Engine\Xoshiro256StarStar::__unserialize()
accepts all-zero state). (iliaal)

- SPL:
. Fixed bug GH-21499 (RecursiveArrayIterator getChildren UAF after parent
free). (Girgias)
Expand Down
4 changes: 4 additions & 0 deletions ext/random/engine_xoshiro256starstar.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ static bool unserialize(void *state, HashTable *data)
}
}

if (UNEXPECTED(s->state[0] == 0 && s->state[1] == 0 && s->state[2] == 0 && s->state[3] == 0)) {
return false;
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
GH-21731: Xoshiro256StarStar::__unserialize() must reject the all-zero state
--FILE--
<?php

try {
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";}}'));
} catch (\Exception $e) {
echo $e->getMessage(), PHP_EOL;
}

?>
--EXPECT--
Invalid serialization data for Random\Engine\Xoshiro256StarStar object
Loading