Skip to content

Fix GH-21731: Random\Engine\Xoshiro256StarStar::__unserialize() accepts all-zero state#21732

Open
iliaal wants to merge 1 commit intophp:PHP-8.4from
iliaal:fix/gh-21731-xoshiro-unserialize-zero-state
Open

Fix GH-21731: Random\Engine\Xoshiro256StarStar::__unserialize() accepts all-zero state#21732
iliaal wants to merge 1 commit intophp:PHP-8.4from
iliaal:fix/gh-21731-xoshiro-unserialize-zero-state

Conversation

@iliaal
Copy link
Copy Markdown
Contributor

@iliaal iliaal commented Apr 12, 2026

Fixes #21731.

Random\Engine\Xoshiro256StarStar::__construct() rejects a seed that would leave the internal state all zero, because xoshiro256** with zero state returns 0 on every call forever. The unserialize callback didn't check the same invariant. A caller feeding a crafted serialized payload through __unserialize() ended up with a live engine that returned 0 from every operation.

Match the constructor: reject the all-zero state from unserialize too. The Mt19937-aliased __unserialize() wrapper maps the false return into the standard "Invalid serialization data for ... object" exception, so the wrapper needs no changes.

…cepts all-zero state

The constructor rejects a seed that would leave the internal state
all zero, because xoshiro256** with zero state produces 0 on every
call forever. The unserialize callback didn't check the same
invariant. A caller feeding a crafted serialized payload through
__unserialize() ended up with a live engine that returned 0 from
every operation.

Match the constructor: reject the all-zero state from the unserialize
callback too. The Mt19937-aliased __unserialize() wrapper turns the
false return into the standard "Invalid serialization data" exception.

Closes phpGH-21731
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant