php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login go to bug id or search bugs for
Bug #70187 [Introduced in PHP 7] Notice: unserialize(): Unexpected end of serialized data
Submitted: 2015-08-03 07:22 UTC Modified: 2015-08-25 09:48 UTC
Votes: 2 4.0 ± 1.0 1 of 2 (50.0%) 1 (100.0%) 1 (100.0%)
From: pagescene at gmail dot com Assigned: dmitry (profile)
Status: Closed Package: Unknown/Other Function
PHP Version: 7.0.0beta2 OS: Windows 7
Private report: No CVE-ID: None
[2015-08-03 07:22 UTC] pagescene at gmail dot com
Description:
------------
Conf: Drupal site (version 7) latest release. Inside Drupal's Views display pages I get:

Notice: unserialize(): Unexpected end of serialized data in ctools_object_cache_get() (line 48 of C:\WWW\int\sites\all\modules\ctools\includes\object-cache.inc).
Notice: unserialize(): Error at offset 15910 of 74156 bytes in ctools_object_cache_get() (line 48 of C:\WWW\int\sites\all\modules\ctools\includes\object-cache.inc).

While editing Drupal's views displays, cTools stores modifications inside Drupal's cache tables before they are saved permanently inside the DB. This functionality is also affected: settings are never saved to the DB and they  revert always to the ones set up previously under PHP 5.6.

Related issue: trying to add a new page to an existing view returns unauthorized message (e.g. you are not authorized to access this page).

All this was working very fine under PHP 5.6 but got introduced in PHP 7.

Any idea what might be going on here? Thanks.

Test script:
---------------
http://www.drupalcontrib.org/api/drupal/contributions%21ctools%21includes%21object-cache.inc/function/ctools_object_cache_get/7

History

[2015-08-03 12:57 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
[2015-08-03 12:57 UTC] cmb@php.net
Have you consulted a Drupal support channel? It is possible that
Drupal 7 is not supposed to be compatible with PHP 7.
[2015-08-03 14:06 UTC] pagescene at gmail dot com
-Status: Feedback +Status: Assigned
[2015-08-03 14:06 UTC] pagescene at gmail dot com
I did submit an issue to Views maintainers but no response yet. The strange thing is that PHP's 5.6 serialize() function manages to serialize the views object in a manner that allows successful unserialization, but the same function fails under PHP 7.
[2015-08-03 17:16 UTC] cmb@php.net
-Assigned To: cmb +Assigned To:
[2015-08-05 19:23 UTC] pagescene at gmail dot com

The error I get is this:

Notice: unserialize(): Error at offset 2101 of 3558 bytes in ***

Under HHVM I get:
Notice: Unable to unserialize: [{the string}]. Expected ':' but got 's'. in ***

The strange thing that there is no : in the specified position.

Allow me to attach the string to be unserialized and that causes the problem:

[2015-08-23 15:56 UTC] jhdxr@php.net
-Status: Open +Status: Feedback
[2015-08-23 15:56 UTC] jhdxr@php.net
I tried to unserialize your string <https://3v4l.org/EYtah>, but failed in all php version, including php5.6. Is there any invisible characters in your original string?
[2015-08-23 16:43 UTC] cmb@php.net
For some reason the serialized string is corrupt. Both
view_display objects declare to have 8 properties, but they only
have 7. The views_display object declares to have 55 properties,
but it has only 51. Fixing these issues manually lets
unserialize() succeed, see <https://3v4l.org/Pvr91>.

So obviously, this is not an issue with unserialize(), but rather
with serialize(). It would be helpful to have a minimal reproduce
script.
[2015-08-23 17:40 UTC] nikic@php.net
If I were to venture a guess, it's because there is an object with a dynamic properties HT, which contains and INDIRECT to and UNDEF. The hashtable count will then include the UNDEF, but it will not be actually present in the properties list.
[2015-08-23 17:42 UTC] nikic@php.net
Here we go: https://3v4l.org/KiLqN

class A { public $b; }$a = new A;
var_dump($a); // force properties HT unset($a->b);
var_dump(serialize($a)); Results in "O:1:"A":1:{}" while it should be "O:1:"A":0:{}". [2015-08-23 19:57 UTC] cmb@php.net -Status: Feedback +Status: Verified [2015-08-25 09:22 UTC] pagescene at gmail dot com Thanks very much to you all for looking into this issue. So do you think this is a PHP 7 bug or does the Drupal Views code need to be adjusted for PHP 7? The error appears only under PHP 7. @nikic@php.net, would you please explain this part from your comment: "t's because there is an object with a dynamic properties HT, which contains and INDIRECT to and UNDEF" .. The View's class definition is here (expand View source item in page): https://api.drupal.org/api/views/includes%21view.inc/7 The ctools_object_cache code (where the view's object gets serialized): http://www.drupalcontrib.org/api/drupal/contributions%21ctools%21includes%21object-cache.inc/7 Thanks. [2015-08-25 09:48 UTC] nikic@php.net -Assigned To: +Assigned To: dmitry [2015-08-25 09:48 UTC] nikic@php.net @pagescene: This is definitely a bug in PHP 7. You shouldn't change the Drupal code for this ;) The problem is basically that in PHP 7 count($array) is no longer precise (i.e. does not match the actual number of elements in the array) in some very limited circumstances. One such case is doing something like count(\$object->getAllProperties()) if there exists some property that was declared on the class and later unset(). In this case the count() will be reported to be one larger than it really is.

@dmitry: Could you take a look at this? Is there some way to fix this short of doing a full table scan beforehand (or serializing the contents into a separate buffer first and counting elements while doing so)?
[2015-08-26 00:27 UTC] dmitry@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=25f9e255264d8196f51a22707e797977e4cd3995
Log: Fixed bug #70187 (Notice: unserialize(): Unexpected end of serialized data)
[2015-08-26 00:27 UTC] dmitry@php.net
-Status: Verified +Status: Closed
[2015-08-26 06:47 UTC] pagescene at gmail dot com
Thanks very much @nikic & @dmitry. I can confirm that the latest commits to php-src fixed the issue. Drupal Views works flawlessly now. All the best :-)
[2015-09-03 18:10 UTC] ab@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=25f9e255264d8196f51a22707e797977e4cd3995
Log: Fixed bug #70187 (Notice: unserialize(): Unexpected end of serialized data)
[2016-07-20 11:36 UTC] davey@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=25f9e255264d8196f51a22707e797977e4cd3995
Log: Fixed bug #70187 (Notice: unserialize(): Unexpected end of serialized data)