Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:1914 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 48512 invoked from network); 22 May 2003 21:44:06 -0000 Received: from unknown (HELO moutng.kundenserver.de) (212.227.126.189) by pb1.pair.com with SMTP; 22 May 2003 21:44:06 -0000 Received: from [212.227.126.160] (helo=mrelayng.kundenserver.de) by moutng.kundenserver.de with esmtp (Exim 3.35 #1) id 19Ixqw-0007Zq-00; Thu, 22 May 2003 23:43:58 +0200 Received: from [217.80.180.225] (helo=[217.80.180.225]) by mrelayng.kundenserver.de with asmtp (Exim 3.35 #1) id 19Ixqv-0007Oy-00; Thu, 22 May 2003 23:43:57 +0200 To: Dmitriy Myshkin Cc: internals@lists.php.net In-Reply-To: <200305211946.h4LJkAj04428@webp5.t3link.com> References: <200305211946.h4LJkAj04428@webp5.t3link.com> Content-Type: multipart/mixed; boundary="=-E/b0qf/m1rWB4qjBmSQA" Organization: Message-ID: <1053639840.53293.14.camel@localhost> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.4 Date: 22 May 2003 23:44:00 +0200 Subject: Re: [PHP-DEV] severe serialize problem From: thekid@thekid.de (Timm Friebe) --=-E/b0qf/m1rWB4qjBmSQA Content-Type: text/plain Content-Transfer-Encoding: 7bit On Wed, 2003-05-21 at 21:46, Dmitriy Myshkin wrote: > an object that is in a namespaced class that is serialized and then > deserialized becomes a "__PHP_Incomplete_Class Object ( > [__PHP_Incomplete_Class_Name]". It seems serialize/deserialize don't > understand namespaces. These patches to php_incomplete_class.h and var_unserializer.re, though not thoroughly tested, fix this. Test script: You will need re2c to compile, see http://www.tildeslash.org/re2c/ - Timm --=-E/b0qf/m1rWB4qjBmSQA Content-Disposition: attachment; filename=php_incomplete_class.h.diff Content-Type: text/x-patch; name=php_incomplete_class.h.diff; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Index: ext/standard/php_incomplete_class.h =================================================================== RCS file: /repository/php4/ext/standard/php_incomplete_class.h,v retrieving revision 1.10 diff -u -r1.10 php_incomplete_class.h --- ext/standard/php_incomplete_class.h 31 Dec 2002 16:07:52 -0000 1.10 +++ ext/standard/php_incomplete_class.h 22 May 2003 21:34:17 -0000 @@ -26,14 +26,29 @@ #define PHP_IC_ENTRY \ BG(incomplete_class) -#define PHP_SET_CLASS_ATTRIBUTES(struc) \ - /* OBJECTS_FIXME: Fix for new object model */ \ - if (Z_OBJCE_P(struc) == BG(incomplete_class)) { \ - class_name = php_lookup_class_name(struc, &name_len, 1); \ - free_class_name = 1; \ - } else { \ - class_name = Z_OBJCE_P(struc)->name; \ - name_len = Z_OBJCE_P(struc)->name_length; \ +#define PHP_SET_CLASS_ATTRIBUTES(struc) \ + if (Z_OBJCE_P(struc) == BG(incomplete_class)) { \ + class_name = php_lookup_class_name(struc, &name_len, 1); \ + free_class_name = 1; \ + } else { \ + if (Z_OBJ_HT_P(struc)->get_class_name == NULL || \ + Z_OBJ_HT_P(struc)->get_class_name(struc, &class_name, &name_len, 0 TSRMLS_CC) != SUCCESS) { \ + zend_class_entry *ce; \ + ce = zend_get_class_entry(struc TSRMLS_CC); \ + if (!ce) { \ + class_name = php_lookup_class_name(struc, &name_len, 1); \ + free_class_name = 1; \ + } \ + if (ce->ns) { \ + zend_make_full_classname(ce, &class_name, &name_len); \ + free_class_name = 1; \ + } else { \ + class_name = Z_OBJCE_P(struc)->name; \ + name_len = Z_OBJCE_P(struc)->name_length; \ + } \ + } else { \ + free_class_name = 1; \ + } \ } #define PHP_CLEANUP_CLASS_ATTRIBUTES() \ --=-E/b0qf/m1rWB4qjBmSQA Content-Disposition: attachment; filename=var_unserializer.re.diff Content-Type: text/x-patch; name=var_unserializer.re.diff; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Index: ext/standard/var_unserializer.re =================================================================== RCS file: /repository/php4/ext/standard/var_unserializer.re,v retrieving revision 1.14 diff -u -r1.14 var_unserializer.re --- ext/standard/var_unserializer.re 18 May 2003 12:08:51 -0000 1.14 +++ ext/standard/var_unserializer.re 22 May 2003 21:35:15 -0000 @@ -353,6 +353,7 @@ int len2; char *class_name; zend_class_entry *ce; + zend_class_entry **pce; int incomplete_class = 0; zval *user_func; @@ -373,50 +374,53 @@ class_name[len] = class_name[len] - 'A' + 'a'; } } - - if (zend_hash_find(CG(class_table), class_name, len2 + 1, (void **) &ce) != SUCCESS) { + + do { + /* Try to find class directly */ + if (zend_lookup_ns_class(class_name, len2, &pce TSRMLS_CC) == SUCCESS) { + ce = *pce; + break; + } + + /* Check for unserialize callback */ if ((PG(unserialize_callback_func) == NULL) || (PG(unserialize_callback_func)[0] == '\0')) { incomplete_class = 1; ce = PHP_IC_ENTRY; - } else { - MAKE_STD_ZVAL(user_func); - ZVAL_STRING(user_func, PG(unserialize_callback_func), 1); - - args[0] = &arg_func_name; - MAKE_STD_ZVAL(arg_func_name); - ZVAL_STRING(arg_func_name, class_name, 1); - - if (call_user_function_ex(CG(function_table), NULL, user_func, &retval_ptr, 1, args, 0, NULL TSRMLS_CC) != SUCCESS) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "defined (%s) but not found", user_func->value.str.val); - incomplete_class = 1; - ce = PHP_IC_ENTRY; - } else { - if (zend_hash_find(CG(class_table), class_name, len2 + 1, (void **) &ce) != SUCCESS) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "(%s) hasn't defined the class it was called for", user_func->value.str.val); - incomplete_class = 1; - ce = PHP_IC_ENTRY; - } else { -#ifdef ZEND_ENGINE_2 - ce = *(zend_class_entry **)ce; /* Bad hack, TBF! */ -#endif - efree(class_name); - } - } + break; + } + + /* Call unserialize callback */ + MAKE_STD_ZVAL(user_func); + ZVAL_STRING(user_func, PG(unserialize_callback_func), 1); + args[0] = &arg_func_name; + MAKE_STD_ZVAL(arg_func_name); + ZVAL_STRING(arg_func_name, class_name, 1); + if (call_user_function_ex(CG(function_table), NULL, user_func, &retval_ptr, 1, args, 0, NULL TSRMLS_CC) != SUCCESS) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "defined (%s) but not found", user_func->value.str.val); + incomplete_class = 1; + ce = PHP_IC_ENTRY; + break; + } + + /* The callback function may have defined the class */ + if (zend_lookup_ns_class(class_name, len2, &pce TSRMLS_CC) == SUCCESS) { + ce = *pce; + break; } - } else { -#ifdef ZEND_ENGINE_2 - ce = *(zend_class_entry **)ce; /* Bad hack, TBF! */ -#endif - efree(class_name); - } + php_error_docref(NULL TSRMLS_CC, E_WARNING, "(%s) hasn't defined the class it was called for", user_func->value.str.val); + incomplete_class = 1; + ce = PHP_IC_ENTRY; + break; + } while (1); + *p = YYCURSOR; elements = object_common1(UNSERIALIZE_PASSTHRU, ce); if (incomplete_class) { php_store_class_name(*rval, class_name, len2); - efree(class_name); } + efree(class_name); return object_common2(UNSERIALIZE_PASSTHRU, elements); } --=-E/b0qf/m1rWB4qjBmSQA--