|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2016-09-09 03:07 UTC] taoguangchen at icloud dot com
Description:
------------
Memory Corruption in During Deserialized-object Destruction
```
if (!process_nested_data(UNSERIALIZE_PASSTHRU, Z_OBJPROP_PP(rval), elements, 1)) {
/* We've got partially constructed object on our hands here. Wipe it. */
if(Z_TYPE_PP(rval) == IS_OBJECT) {
zend_hash_clean(Z_OBJPROP_PP(rval));
}
ZVAL_NULL(*rval);
return 0;
}
```
If object deserialization fails, the broken-object's properties will be cleaned. But the object still stored in objects_store, then destructor call with uninitialized properties in during shutdown, that result in memory corruption.
PoC:
```
<?php
class obj {
var $ryat;
public function __destruct() {
$this->ryat = null;
}
}
$poc = 'O:3:"obj":1:{';
unserialize($poc);
?>
```
Fix:
You need to set the broken-object's destructor_called into 1.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 10:00:01 2025 UTC |
Fix: ``` if(Z_TYPE_PP(rval) == IS_OBJECT) { zend_hash_clean(Z_OBJPROP_PP(rval)); + EG(objects_store).object_buckets[Z_OBJ_HANDLE_PP(rval)].destructor_called = 1; } ```You can also consider calling zend_object_store_ctor_failed() ``` if(Z_TYPE_PP(rval) == IS_OBJECT) { zend_hash_clean(Z_OBJPROP_PP(rval)); + zend_object_store_ctor_failed(*rval, TSRMLS_CC); } ```