[php-src] PR #22469: Keep the object alive across jsonSerialize() in json_encode()

From: Date: Fri, 26 Jun 2026 13:32:22 +0000
Subject: [php-src] PR #22469: Keep the object alive across jsonSerialize() in json_encode()
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-36670@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/22469 Author: iliaal json_encode() can use-after-free a JsonSerializable object when its jsonSerialize() triggers a user error handler that frees the object, for example by nulling a reference that aliases the encoded array slot. php_json_encode_serializable_object() holds a raw pointer to the object across the call and then reads its recursion guard and compares identity against the return value. Fix: hold a reference on the object across the call. The array path already guards against this with a ZVAL_COPY ("Avoid modifications (and potential freeing) of the array... when a jsonSerialize() method is invoked"); the JsonSerializable object path did not.

« previous php.git-pulls (#36670) next »