Skip to content

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

Closed
iliaal wants to merge 1 commit intoPHP-8.4from
fix/gh-21731-xoshiro-unserialize-zero-state
Closed

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

Conversation

@iliaal
Copy link
Copy Markdown
Owner

@iliaal iliaal commented Apr 12, 2026

Fixes php#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
@iliaal iliaal force-pushed the fix/gh-21731-xoshiro-unserialize-zero-state branch from 5f7278f to cd7de3e Compare April 12, 2026 01:34
@iliaal
Copy link
Copy Markdown
Owner Author

iliaal commented Apr 12, 2026

Submitted upstream as php#21732

@iliaal iliaal closed this Apr 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant