Bug #80411 [Com]: References to null-serialized object break serialize()

From: Date: Fri, 27 Nov 2020 14:53:02 +0000
Subject: Bug #80411 [Com]: References to null-serialized object break serialize()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-230686@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80411&edit=1

 ID:                 80411
 Comment by:         whaanstra at eljakim dot nl
 Reported by:        whaanstra at eljakim dot nl
 Summary:            References to null-serialized object break
                     serialize()
 Status:             Closed
 Type:               Bug
 Package:            *General Issues
 PHP Version:        7.4.12
 Block user comment: N
 Private report:     N

 New Comment:

This fix is not quite the same behaviour as pre-7.3.4, since the second element of the reconstructed
array is no longer a reference to the first element.


Previous Comments:
------------------------------------------------------------------------
[2020-11-25 16:25:22] nikic@php.net

Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=2fb12be84cae8c77380198cb473e816c8bd47707
Log: Fixed bug #80411

------------------------------------------------------------------------
[2020-11-24 16:54:37] whaanstra at eljakim dot nl

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 this bug report at https://bugs.php.net/bug.php?id=80411&edit=1


Thread (4 messages)

« previous php.bugs (#230686) next »