Skip to content
Closed
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
6 changes: 6 additions & 0 deletions ext/random/engine_xoshiro256starstar.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ static bool unserialize(void *state, HashTable *data)
}
}

/* An all-zero state generates zero forever. The constructor rejects
* such a seed; reject it here for symmetry. */
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,21 @@
--TEST--
GH-21731: Xoshiro256StarStar::__unserialize() must reject the all-zero state
--FILE--
<?php declare(strict_types = 1);

use Random\Engine\Xoshiro256StarStar;

try {
$engine = new Xoshiro256StarStar(42);
$engine->__unserialize([
[],
['0000000000000000', '0000000000000000', '0000000000000000', '0000000000000000'],
]);
echo "FAIL: __unserialize() accepted zero state\n";
} catch (\Exception $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}

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