Repository navigation
Conversation
|
On the PR head (ef25b3a) ASan reports a heap-use-after-free here, while the base (fd3a97d) and current master are fine. The outer object has no closing <?php
class T { public function __unserialize(array $data): void {} }
class D { public function __destruct() { var_dump(unserialize('R:2;')); } }
// the closing } of the outer object is missing
var_dump(@unserialize('O:1:"T":2:{i:0;s:5:"hello";i:1;O:1:"D":0:{}'));Run with |
|
Ah, indeed. A failed record's data array now stays in the unserialize context until var_destroy(), like a queued one, so the destructor can no longer reach an element it already released. The same UAF was reachable before this PR when an element after the nested object is malformed; both cases are now in __unserialize_malformed_nested_destructor.phpt. |
Check the closing brace before queuing __unserialize() or __wakeup(). Incomplete object records must use the same cleanup as invalid property data, including destructor suppression. The __unserialize() data array of a failed record now stays in the unserialize context until var_destroy() instead of being released at once, so a destructor of a nested object cannot resolve a back-reference to an element the array already released.
bukka
left a comment
There was a problem hiding this comment.
This looks correct and fixes the issues.
|
I merged it as it conflicts with my other work so want to rebase it on this... |
The unserializer now checks each object's closing brace before queuing
__unserialize()or__wakeup(), so incomplete objects skip their callback and destructor. Related to #21716, which changes when already-queued callbacks are drained.