Repository navigation
[DeepClone] Reject more internal classes that keep their state out of their properties - #708
Merged
Merged
Conversation
nicolas-grekas
force-pushed
the
deepclone-internal-state
branch
from
September 29, 2026 10:46
7ef7d08 to
9b36ac3
Compare
nicolas-grekas
added a commit
to symfony/php-ext-deepclone
that referenced
this pull request
Sep 29, 2026
…from_array() (nicolas-grekas) This PR was merged into the main branch. Discussion ---------- Reject classes that keep their state internally in deepclone_from_array() Builds on #50 and #52. `deepclone_to_array()` and `deepclone_hydrate()` reject the internal classes that keep their state out of their properties and declare no serialization API, like `Redis`, `Imagick` or the AMQP and Relay classes, but `deepclone_from_array()` created them when a payload named them, eg one produced by the polyfill. `unserialize()` creates them that way too, and some crash PHP then: `RedisCluster::acl()` or `ImagickDraw::affine()` segfault on such objects, and a `Relay\Table` does when destroyed. The class lookup of `deepclone_from_array()` now applies the same rule, which the three functions share in one helper, and throws `NotInstantiableException`. User classes that extend such a class without declaring a serialization API are rejected too, in all three functions: a subclass of `RedisCluster` crashed the same way. For user classes, that's one more flag test per class and call. `IteratorIterator` and the other internal iterators wrapping another one are rejected too, where #50 created them like `unserialize()` does, and so are their user subclasses. Payloads that carry serialized strings still create whatever `unserialize()` creates from them, unless `$allowed_classes` excludes it. The polyfill gets the same change in symfony/polyfill#708, for the classes of the extensions it knows, as it can't tell which classes keep their state internally. Commits ------- f7b2c3c Reject classes that keep their state internally in deepclone_from_array()
nicolas-grekas
force-pushed
the
deepclone-internal-state
branch
from
September 29, 2026 15:25
9b36ac3 to
ba91111
Compare
…_from_array() and deepclone_hydrate()
…deepclone_from_array() and deepclone_hydrate() (nicolas-grekas) This PR was merged into the 1.x branch. Discussion ---------- [DeepClone] Reject and create classes like the extension in deepclone_from_array() and deepclone_hydrate() | Q | A | ------------- | --- | Branch? | 1.x | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT `deepclone_from_array()` now creates `IteratorIterator` and the other classes whose state `serialize()` loses, like `unserialize()` and the extension do, while `deepclone_to_array()` keeps rejecting them. `deepclone_hydrate()` creates their user subclasses, like the extension that checks only internal ones. Classes extending an anonymous one through `class_alias()` are rejected, like `serialize()` does, and serialized objects of a payload that `unserialize()` fails to decode throw the extension's `ValueError`, with what `unserialize()` threw as previous exception. Messages match the extension's too: declared class names, `Type "X"` in `deepclone_hydrate()`, names cut at NUL bytes. This builds on #699. The extension gets the matching changes in symfony/php-ext-deepclone#50. Commits ------- 0fab20e [DeepClone] Reject and create classes like the extension in deepclone_from_array() and deepclone_hydrate()
… their properties
nicolas-grekas
force-pushed
the
deepclone-internal-state
branch
from
September 29, 2026 15:38
ba91111 to
14a31d4
Compare
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.
Builds on #703.
The extension rejects the internal classes that keep their state out of their properties and declare no serialization API, in
deepclone_to_array(),deepclone_hydrate()and, with symfony/php-ext-deepclone#53,deepclone_from_array(). The polyfill can't see which classes do so and knew only the ones of zip, xmlreader, xmlwriter, snmp and tidy: it exported aRedisor anImagickwithout its state, anddeepclone_from_array()created them, which can crash PHP, eg when a bareRelay\Tableis destroyed or a clone of a bareAMQPConnectionis dumped. It now also knows the classes of the redis, relay, imagick, amqp, apcu and msgpack extensions, and rejects them before creating a prototype, together with their user subclasses that declare no serialization API. Classes of other extensions stay accepted.Like the extension,
deepclone_from_array()now also rejects the internal classes whose stateserialize()loses, likeIteratorIterator, asdeepclone_hydrate()already did, and both reject their user subclasses too, unless they declare a serialization API.