|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2021-06-17 08:49 UTC] j7ur8 at qq dot com
Description:
------------
bad unserialize string makes __wakeup ineffective.
Success:
7.0.15 - 7.0.33, 7.1.1 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.28, 7.4.0 - 7.4.16, 8.0.0 - 8.0.3
Fail:
5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.14, 7.1.0
Test script:
---------------
// https://3v4l.org/4nZUm
<?php
class D{
public $flag=True;
public function __get($a){
if($this->flag){
echo 'flag';
}else{
echo 'hint';
}
}
public function __wakeup(){
$this->flag = False;
}
}
class C{
public function __destruct(){
echo $this->c->b;
}
}
@unserialize('O:1:"C":1:{s:1:"c";O:1:"D":0:{};N;}');
Expected result:
----------------
hint
Actual result:
--------------
flag
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 04:00:01 2025 UTC |
So, unserialize doesn't guarantee __wakeup executed before __destruct? The string sequence i provided is illegal(at least not so correct): ` O:1:"C":1:{s:1:"c";O:1:"D":0:{};N;} ` // https://3v4l.org/M9bQJ the orders is: >PHP Notice: unserialize(): Error at offset 31 of 35 bytes in >Notice: unserialize(): Error at offset 31 of 35 bytes in >C::__destruct >D::__get(b) >D::__wakeup >D::__destruct as we can see, __get executed before __wakeup. And if the sequence is correct: ` O:1:"C":1:{s:1:"c";O:1:"D":0:{}} ` // https://3v4l.org/UMahR the orders is : >D::__wakeup >C::__destruct >D::__get(b) >D::__destruct So, This is reasonable?