standard: Pass unserialize('') through the regular path - #23827
Merged
Merged
Conversation
Previously `unserialize()` with an empty string as input was handled specially, returning `false` (indicating an error), but without emitting an associated warning. We can just pass it through the regular path, which will also return `false` (including the warning) and will also avoid a check that is almost never taken in practice. Fixes php#23780.
ndossche
reviewed
Sep 21, 2026
| HashTable *class_hash = NULL, *prev_class_hash; | ||
| zend_long prev_max_depth, prev_cur_depth; | ||
|
|
||
| if (buf_len == 0) { |
Member
There was a problem hiding this comment.
This rings a bell though. I think I recall a case somewhere in the codebase wshere a non-null terminated string was passed to unserialize; that might need fixing (if it's still there and my memory serves me well) before proceeding with this.
Member
Author
There was a problem hiding this comment.
php_unserialize_with_options() is only ever called from:
phar_metadata_tracker_unserialize_or_copy()PHP_FUNCTION(unserialize)
in both cases the input is a zend_string which would already be malformed when not terminated. And php_var_unserialize_internal() also immediately bails out when YYCURSOR >= YYLIMIT, which is the case for an empty input.
So this should be safe.
ndossche
approved these changes
Sep 22, 2026
TimWolla
added a commit
that referenced
this pull request
Sep 22, 2026
* PHP-8.6:
standard: Pass `unserialize('')` through the regular path (#23827)
sebastianbergmann
added a commit
to sebastianbergmann/phpunit
that referenced
this pull request
Sep 23, 2026
As of php/php-src#23827, unserialize('') emits a warning, which our error handler converts to an exception
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously
unserialize()with an empty string as input was handled specially, returningfalse(indicating an error), but without emitting an associated warning. We can just pass it through the regular path, which will also returnfalse(including the warning) and will also avoid a check that is almost never taken in practice.Fixes #23780.