Horde-Kolab-Storage - unserialize issue

Remi Collet <[email protected]>
Newsgroups gmane.comp.horde.devel
Message-ID <[email protected]>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

With PHP 5.6.0 test suite fails :

There were 51 errors:

1) Horde_Kolab_Storage_Unit_Data_BaseTest::testDefaultType
Erroneous data format for unserializing 'Horde_Mime_Part'

/dev/shm/BUILD/php-horde-Horde-Kolab-Storage-2.1.0/Horde_Kolab_Storage-2.1.0/lib/Horde/Kolab/Storage/Driver/Mock/Data.php:103
...


Digging in this issue.

First: you should be awarer that "serialized" data is a very bad
pratice for storage... no warranty to work accross various versions.

See the recent discussion about the "unserialize" regression/issue...

The test/Horde/Kolab/Storage/fixtures/event.struct contains:
O:15:"Horde_Mime_Part":...

Which is wrong, as Horde_Mime_Part implements Serializable.
(should be C:... with PHP > 5.4)


Proof.

<?php
require 'Horde/Autoloader/Default.php';
$txt = file_get_contents("event.struct");
var_dump($ser = base64_decode($txt));
$obj = unserialize($ser);
var_dump($obj);
var_dump($ser = serialize($obj));

PHP Fatal error:  Call to a member function getArrayCopy() on a
non-object in /usr/share/pear/Horde/Mime/Part.php on line 2321

Analyse: with "O:..;" the unserialize method is not used.
So the object is create, but without the correct unserializer.


Fixing the fixture file.

I add in the Horde_Mime_Part the fixit method

   public function fixit()
   {
      if (is_array($this->_contentTypeParams)) {
         echo "Fix\n";
         $this->_contentTypeParams =
    new Horde_Support_CaseInsensitiveArray($this->_contentTypeParams);
      }
      foreach($this->_parts as $i => $p) {
          echo "Part $i\n";
          $p->fixit();
      }
   }

This allow to fix the unserialized object,
and then to serialize it and save it.

Then the new fixture file contains:
C:15:"Horde_Mime_Part":978:{a:20:{i:0;i:1

Then this file can be used with PHP 5.4, 5.5 and 5.6.


The attached patch add this "fixed" fixture file, and use it.

Test suite pass with php 5.3, 5.4, 5.5, 5.6


Can you please review it ?

Regards,
Remi.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlPvjaQACgkQYUppBSnxahgE7ACg1N3PdQpiPc/up0PKTM00vE5s
sAAAoPi/ORQN8PPW2+C45aUjNA3DZ669
=VuPw
-----END PGP SIGNATURE-----

-- 
dev mailing list
Frequently Asked Questions: http://wiki.horde.org/FAQ
To unsubscribe, mail: [email protected]
Horde_Kolab_Storage-php54.patch (text/x-patch, 2.5 KB)
diff -up test/Horde/Kolab/Storage/TestCase.php.old test/Horde/Kolab/Storage/TestCase.php
--- test/Horde/Kolab/Storage/TestCase.php.old	2014-08-16 18:22:51.556008063 +0200
+++ test/Horde/Kolab/Storage/TestCase.php	2014-08-16 18:25:17.171626554 +0200
@@ -655,8 +655,13 @@ extends PHPUnit_Framework_TestCase
 
     protected function getDefaultEventData($add = '')
     {
+        if (version_compare(PHP_VERSION, '5.4.0', 'lt')) {
+            $file = __DIR__ . '/fixtures/event.struct';
+        } else {
+            $file = __DIR__ . '/fixtures/event.struct.php54';
+        }
         return array(
-            'structure' => __DIR__ . '/fixtures/event.struct',
+            'structure' => $file,
             'parts' => array(
                 '2' => array(
                     'file' => __DIR__ . '/fixtures/event' . $add . '.xml.qp',
diff -up test/Horde/Kolab/Storage/fixtures/event.struct.php54.old test/Horde/Kolab/Storage/fixtures/event.struct.php54
--- test/Horde/Kolab/Storage/fixtures/event.struct.php54.old	2014-08-16 18:23:02.600054958 +0200
+++ test/Horde/Kolab/Storage/fixtures/event.struct.php54	2014-08-16 18:20:31.829414814 +0200
@@ -0,0 +1 @@
+QzoxNToiSG9yZGVfTWltZV9QYXJ0Ijo5Nzg6e2E6MjA6e2k6MDtpOjE7aToxO3M6OToibXVsdGlwYXJ0IjtpOjI7czo1OiJtaXhlZCI7aTozO3M6NjoiYmluYXJ5IjtpOjQ7YTowOnt9aTo1O3M6MDoiIjtpOjY7czowOiIiO2k6NzthOjA6e31pOjg7YToxOntzOjg6ImJvdW5kYXJ5IjtzOjE0OiI9XzFha21tdDNpaTZ2NCI7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=
\ No newline at end of file
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.