php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57965 The information on object type is lost
Submitted: 2007-12-12 02:16 UTC Modified: 2008-07-23 16:28 UTC
From: develar at gmail dot com Assigned:
Status: Closed Package: amfext (PECL)
PHP Version: Irrelevant OS: Vista
Private report: No CVE-ID: None
 [2007-12-12 02:16 UTC] develar at gmail dot com
Description:
------------
Object type after encode/decode is lost. Only first item in associative array is save. If the array not associative all works, but is necessary an associative array.

Reproduce code:
---------------
<?php

class Types_authenticator_admin_cms
{
	public $attributes;
}

class Attribute_authenticator_admin_cms
{
	public $name;
}

$result = unserialize('O:29:"Types_authenticator_admin_cms":1:{s:10:"attributes";a:3:{i:50;a:1:{i:0;O:33:"Attribute_authenticator_admin_cms":1:{s:4:"name";s:4:"Name";}}i:13;a:2:{i:0;O:33:"Attribute_authenticator_admin_cms":1:{s:4:"name";s:4:"Name";}i:1;O:33:"Attribute_authenticator_admin_cms":1:{s:4:"name";s:4:"Text";}}i:1;a:1:{i:0;O:33:"Attribute_authenticator_admin_cms":1:{s:4:"name";s:4:"Name";}}}}');

echo "before encode/decode\n\n";
print_r($result);

echo "\n\nafter encode/decode\n\n";
$big_endian = pack('d', 1) == "\0\0\0\0\0\0\360\77" ? 2 : 0;
print_r(amf_decode(amf_encode($result, $big_endian | 1), $big_endian));

?>

Expected result:
----------------
before encode/decode

Types_authenticator_admin_cms Object
(
    [attributes] => Array
        (
            [50] => Array
                (
                    [0] => Attribute_authenticator_admin_cms Object
                        (
                            [name] => Name
                        )

                )

            [13] => Array
                (
                    [0] => Attribute_authenticator_admin_cms Object
                        (
                            [name] => Name
                        )

                    [1] => Attribute_authenticator_admin_cms Object
                        (
                            [name] => Text
                        )

                )

            [1] => Array
                (
                    [0] => Attribute_authenticator_admin_cms Object
                        (
                            [name] => Name
                        )

                )

        )

)


after encode/decode

Types_authenticator_admin_cms Object
(
    [attributes] => stdClass Object
        (
            [50] => Array
                (
                    [0] => Attribute_authenticator_admin_cms Object
                        (
                            [name] => Name
                        )

                )

            [13] => Array
                (
                    [0] => Attribute_authenticator_admin_cms Object
                        (
                            [name] => Name
                        )

                    [1] => Attribute_authenticator_admin_cms Object
                        (
                            [name] => Text
                        )

                )

            [1] => Array
                (
                    [0] => Attribute_authenticator_admin_cms Object
                        (
                            [name] => Name
                        )

                )

        )

)


Actual result:
--------------
before encode/decode

Types_authenticator_admin_cms Object
(
    [attributes] => Array
        (
            [50] => Array
                (
                    [0] => Attribute_authenticator_admin_cms Object
                        (
                            [name] => Name
                        )

                )

            [13] => Array
                (
                    [0] => Attribute_authenticator_admin_cms Object
                        (
                            [name] => Name
                        )

                    [1] => Attribute_authenticator_admin_cms Object
                        (
                            [name] => Text
                        )

                )

            [1] => Array
                (
                    [0] => Attribute_authenticator_admin_cms Object
                        (
                            [name] => Name
                        )

                )

        )

)


after encode/decode

Types_authenticator_admin_cms Object
(
    [attributes] => stdClass Object
        (
            [50] => Array
                (
                    [0] => Attribute_authenticator_admin_cms Object
                        (
                            [name] => Name
                        )

                )

            [13] => Array
                (
                    [0] => stdClass Object
                        (
                            [name] => Name
                        )

                    [1] => stdClass Object
                        (
                            [name] => Text
                        )

                )

            [1] => Array
                (
                    [0] => stdClass Object
                        (
                            [name] => Name
                        )

                )

        )

)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-02-13 01:50 UTC] julius at tacticsoft dot net
Has this been looked at, has anyone found a fix?
 [2008-07-10 19:34 UTC] alex dot demidovich at gmail dot com
No, the problem is different.

During serializing of arrays the amf3_serialize_array function  registers "completely" anonymous class without incrementing an internal counter of classes. This leads to difference between class indexes and their real position, which results in wrong decoding...

To fix the issue, change the following (amf.c, line 1812):

			 /*  string array or not sequenced array => associativ */
			 /* if(num_count > 0 && (str_count > || max_index != num_count-1) */
			if((str_count > 0 && num_count == 0) || (num_count > 0 && max_index != (int)num_count-1))
			{
				amf3_write_objecthead(buf, AMF_INLINE_ENTITY|AMF_INLINE_CLASS|AMF_CLASS_DYNAMIC); 
				var_hash->nextClassIndex++;
				amf3_write_emptystring(buf AMFTSRMLS_CC);  /*  classname=" */


"var_hash->nextClassIndex++;" has to be added....
 [2008-07-23 16:28 UTC] pit at sssup dot it
Thank you for your bug report. This issue has been fixed
in the latest released version of the package, which you can download at
http://pecl.php.net/get/amfext

Applied code from bug sumbit
 [2008-07-30 03:58 UTC] julius at tacticsoft dot net
Thank you very much!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 11:01:30 2024 UTC