Bug #80411 [NEW]: References to null-serialized object break serialize()
From: whaanstra at eljakim dot nl
Operating system:
PHP version: 7.4.12
Package: *General Issues
Bug Type: Bug
Bug description:References to null-serialized object break serialize()
Description:
------------
The reference to the UnSerializable object is serialized as a null,
instead of as a reference. In addition, the serializer still sees it as
a reference, causing the count of reference-able objects to be off. In
my test script, $recovered[3] references $recovered[1] instead of
$recovered[2].
This might be related to https://bugs.php.net/bug.php?id=77302, which
also involved an empty serialize() method, and was fixed in the same
version this was introduced, namely 7.3.4.
Version comparison: https://3v4l.org/YD9fS
Test script:
---------------
class UnSerializable implements Serializable
{
public function serialize() {}
public function unserialize($serialized) {}
}
$unser = new UnSerializable();
$arr = [$unser];
$arr[] = &$arr[0];
$arr[] = 'endcap';
$arr[] = &$arr[2];
$data = serialize($arr);
echo $data . PHP_EOL;
$recovered = unserialize($data);
var_export($recovered);
Expected result:
----------------
a:4:{i:0;N;i:1;R:2;i:2;s:6:"endcap";i:3;R:3;}
array (
0 => NULL,
1 => NULL,
2 => 'endcap',
3 => 'endcap',
)
Actual result:
--------------
a:4:{i:0;N;i:1;N;i:2;s:6:"endcap";i:3;R:3;}
array (
0 => NULL,
1 => NULL,
2 => 'endcap',
3 => NULL,
)
--
Edit bug report at https://bugs.php.net/bug.php?id=80411&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80411&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80411&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80411&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80411&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80411&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80411&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80411&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80411&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80411&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80411&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80411&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80411&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80411&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80411&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80411&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80411&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80411&r=mysqlcfg
Thread (4 messages)
- whaanstra at eljakim dot nl