How to repair a serialized string which has been corrupted by an incorrect byte count length?

后端 未结 15 2082
后悔当初
后悔当初 2020-11-22 11:46

I am using Hotaru CMS with the Image Upload plugin, I get this error if I try to attach an image to a post, otherwise there is no error:

unserialize()

15条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-22 12:28

    the official docs says it should return false and set E_NOTICE

    but since you got error then the error reporting is set to be triggered by E_NOTICE

    here is a fix to allow you detect false returned by unserialize

    $old_err=error_reporting(); 
    error_reporting($old_err & ~E_NOTICE);
    $object = unserialize($serialized_data);
    error_reporting($old_err);
    

    you might want to consider use base64 encode/decode

    $string=base64_encode(serialize($obj));
    unserialize(base64_decode($string));
    

提交回复
热议问题