Repository navigation
Make Redis, RedisArray, RedisCluster and RedisSentinel not serializable - #2938
Merged
michael-grunder merged 2 commits intoSep 29, 2026
Merged
Conversation
serialize() turned them into empty objects, and unserialize() created objects without their connection, which can crash, eg calling acl() on such a RedisCluster segfaults. On PHP 8.1+, both now throw instead.
yatsukhnenko
approved these changes
Sep 29, 2026
Member
|
This PR looks good, but only protects the classes when PHP >= 8.1 I had to look it up but apparently the older way is as follows: static inline void redis_class_deny_serialization(zend_class_entry *ce) {
#if PHP_VERSION_ID < 80100
ce->serialize = zend_class_serialize_deny;
ce->unserialize = zend_class_unserialize_deny;
#endif
}Could use the above function after class registration. I'm also happy to merge this as-is and then add that in a subsequent commit. |
ZEND_ACC_NOT_SERIALIZABLE exists since PHP 8.1. Before, the zend_class_(un)serialize_deny handlers make serialize() throw, and unserialize() too for the C: format, while the O: format fails with a warning without creating the object.
Contributor
Author
|
Thanks, PR updated: before PHP 8.1, the classes now get the deny handlers, and the test runs on 7.4 and 8.0 too. |
This was referenced Sep 29, 2026
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.
serialize()turns these objects into empty ones, andunserialize()creates them without their connection, which can crash PHP:This flags them with
@not-serializable, so that both throw, like forPDOorCurlHandle, and like php/php-src#21694 did forXMLWriter,XMLReader,SNMPandtidy. Serializers that honor the flag, like symfony/php-ext-deepclone, then reject them too. Before PHP 8.1, which has no such flag, they get the handlers that deny serialization instead.