mirror of
https://github.com/php/php-src.git
synced 2026-03-26 09:12:14 +01:00
- Fixed #55798: serialize followed by unserialize with numeric object prop.
gives integer prop.
This commit is contained in:
18
ext/standard/tests/serialize/bug55798.phpt
Normal file
18
ext/standard/tests/serialize/bug55798.phpt
Normal file
@@ -0,0 +1,18 @@
|
||||
--TEST--
|
||||
Bug #55798 (serialize followed by unserialize with numeric object prop. gives integer prop)
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$a = new stdClass();
|
||||
$a->{0} = 'X';
|
||||
$a->{1} = 'Y';
|
||||
var_dump(serialize($a));
|
||||
var_dump($a->{0});
|
||||
$b = unserialize(serialize($a));
|
||||
var_dump(serialize($b));
|
||||
var_dump($b->{0});
|
||||
--EXPECT--
|
||||
string(51) "O:8:"stdClass":2:{s:1:"0";s:1:"X";s:1:"1";s:1:"Y";}"
|
||||
string(1) "X"
|
||||
string(51) "O:8:"stdClass":2:{s:1:"0";s:1:"X";s:1:"1";s:1:"Y";}"
|
||||
string(1) "X"
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Generated by re2c 0.13.5 on Sat Sep 18 17:59:40 2010 */
|
||||
/* Generated by re2c 0.13.5 on Wed Sep 28 15:27:03 2011 */
|
||||
#line 1 "ext/standard/var_unserializer.re"
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
@@ -264,7 +264,7 @@ static inline size_t parse_uiv(const unsigned char *p)
|
||||
#define UNSERIALIZE_PARAMETER zval **rval, const unsigned char **p, const unsigned char *max, php_unserialize_data_t *var_hash TSRMLS_DC
|
||||
#define UNSERIALIZE_PASSTHRU rval, p, max, var_hash TSRMLS_CC
|
||||
|
||||
static inline int process_nested_data(UNSERIALIZE_PARAMETER, HashTable *ht, long elements)
|
||||
static inline int process_nested_data(UNSERIALIZE_PARAMETER, HashTable *ht, long elements, int objprops)
|
||||
{
|
||||
while (elements-- > 0) {
|
||||
zval *key, *data, **old_data;
|
||||
@@ -293,7 +293,8 @@ static inline int process_nested_data(UNSERIALIZE_PARAMETER, HashTable *ht, long
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (Z_TYPE_P(key)) {
|
||||
if (!objprops) {
|
||||
switch (Z_TYPE_P(key)) {
|
||||
case IS_LONG:
|
||||
if (zend_hash_index_find(ht, Z_LVAL_P(key), (void **)&old_data)==SUCCESS) {
|
||||
var_push_dtor(var_hash, old_data);
|
||||
@@ -306,6 +307,12 @@ static inline int process_nested_data(UNSERIALIZE_PARAMETER, HashTable *ht, long
|
||||
}
|
||||
zend_symtable_update(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, &data, sizeof(data), NULL);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
/* object properties should include no integers */
|
||||
convert_to_string(key);
|
||||
zend_hash_update(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, &data,
|
||||
sizeof data, NULL);
|
||||
}
|
||||
|
||||
zval_dtor(key);
|
||||
@@ -373,7 +380,7 @@ static inline int object_common2(UNSERIALIZE_PARAMETER, long elements)
|
||||
zval *retval_ptr = NULL;
|
||||
zval fname;
|
||||
|
||||
if (!process_nested_data(UNSERIALIZE_PASSTHRU, Z_OBJPROP_PP(rval), elements)) {
|
||||
if (!process_nested_data(UNSERIALIZE_PASSTHRU, Z_OBJPROP_PP(rval), elements, 1)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -407,7 +414,7 @@ PHPAPI int php_var_unserialize(UNSERIALIZE_PARAMETER)
|
||||
|
||||
|
||||
|
||||
#line 411 "ext/standard/var_unserializer.c"
|
||||
#line 418 "ext/standard/var_unserializer.c"
|
||||
{
|
||||
YYCTYPE yych;
|
||||
|
||||
@@ -436,9 +443,9 @@ yy2:
|
||||
default: goto yy3;
|
||||
}
|
||||
yy3:
|
||||
#line 733 "ext/standard/var_unserializer.re"
|
||||
#line 740 "ext/standard/var_unserializer.re"
|
||||
{ return 0; }
|
||||
#line 442 "ext/standard/var_unserializer.c"
|
||||
#line 449 "ext/standard/var_unserializer.c"
|
||||
yy4:
|
||||
yych = *(YYMARKER = ++YYCURSOR);
|
||||
switch (yych) {
|
||||
@@ -501,13 +508,13 @@ yy13:
|
||||
}
|
||||
yy14:
|
||||
++YYCURSOR;
|
||||
#line 727 "ext/standard/var_unserializer.re"
|
||||
#line 734 "ext/standard/var_unserializer.re"
|
||||
{
|
||||
/* this is the case where we have less data than planned */
|
||||
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Unexpected end of serialized data");
|
||||
return 0; /* not sure if it should be 0 or 1 here? */
|
||||
}
|
||||
#line 511 "ext/standard/var_unserializer.c"
|
||||
#line 518 "ext/standard/var_unserializer.c"
|
||||
yy16:
|
||||
yych = *++YYCURSOR;
|
||||
goto yy3;
|
||||
@@ -571,7 +578,7 @@ yy22:
|
||||
}
|
||||
yy23:
|
||||
++YYCURSOR;
|
||||
#line 610 "ext/standard/var_unserializer.re"
|
||||
#line 617 "ext/standard/var_unserializer.re"
|
||||
{
|
||||
size_t len, len2, len3, maxlen;
|
||||
long elements;
|
||||
@@ -688,7 +695,7 @@ yy23:
|
||||
|
||||
return object_common2(UNSERIALIZE_PASSTHRU, elements);
|
||||
}
|
||||
#line 692 "ext/standard/var_unserializer.c"
|
||||
#line 699 "ext/standard/var_unserializer.c"
|
||||
yy25:
|
||||
yych = *++YYCURSOR;
|
||||
switch (yych) {
|
||||
@@ -747,7 +754,7 @@ yy29:
|
||||
}
|
||||
yy30:
|
||||
++YYCURSOR;
|
||||
#line 602 "ext/standard/var_unserializer.re"
|
||||
#line 609 "ext/standard/var_unserializer.re"
|
||||
{
|
||||
|
||||
INIT_PZVAL(*rval);
|
||||
@@ -755,7 +762,7 @@ yy30:
|
||||
return object_common2(UNSERIALIZE_PASSTHRU,
|
||||
object_common1(UNSERIALIZE_PASSTHRU, ZEND_STANDARD_CLASS_DEF_PTR));
|
||||
}
|
||||
#line 759 "ext/standard/var_unserializer.c"
|
||||
#line 766 "ext/standard/var_unserializer.c"
|
||||
yy32:
|
||||
yych = *++YYCURSOR;
|
||||
switch (yych) {
|
||||
@@ -813,7 +820,7 @@ yy36:
|
||||
}
|
||||
yy37:
|
||||
++YYCURSOR;
|
||||
#line 582 "ext/standard/var_unserializer.re"
|
||||
#line 589 "ext/standard/var_unserializer.re"
|
||||
{
|
||||
long elements = parse_iv(start + 2);
|
||||
/* use iv() not uiv() in order to check data range */
|
||||
@@ -827,13 +834,13 @@ yy37:
|
||||
|
||||
array_init_size(*rval, elements);
|
||||
|
||||
if (!process_nested_data(UNSERIALIZE_PASSTHRU, Z_ARRVAL_PP(rval), elements)) {
|
||||
if (!process_nested_data(UNSERIALIZE_PASSTHRU, Z_ARRVAL_PP(rval), elements, 0)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return finish_nested_data(UNSERIALIZE_PASSTHRU);
|
||||
}
|
||||
#line 837 "ext/standard/var_unserializer.c"
|
||||
#line 844 "ext/standard/var_unserializer.c"
|
||||
yy39:
|
||||
yych = *++YYCURSOR;
|
||||
switch (yych) {
|
||||
@@ -891,7 +898,7 @@ yy43:
|
||||
}
|
||||
yy44:
|
||||
++YYCURSOR;
|
||||
#line 553 "ext/standard/var_unserializer.re"
|
||||
#line 560 "ext/standard/var_unserializer.re"
|
||||
{
|
||||
size_t len, maxlen;
|
||||
char *str;
|
||||
@@ -920,7 +927,7 @@ yy44:
|
||||
ZVAL_STRINGL(*rval, str, len, 0);
|
||||
return 1;
|
||||
}
|
||||
#line 924 "ext/standard/var_unserializer.c"
|
||||
#line 931 "ext/standard/var_unserializer.c"
|
||||
yy46:
|
||||
yych = *++YYCURSOR;
|
||||
switch (yych) {
|
||||
@@ -978,7 +985,7 @@ yy50:
|
||||
}
|
||||
yy51:
|
||||
++YYCURSOR;
|
||||
#line 525 "ext/standard/var_unserializer.re"
|
||||
#line 532 "ext/standard/var_unserializer.re"
|
||||
{
|
||||
size_t len, maxlen;
|
||||
char *str;
|
||||
@@ -1006,7 +1013,7 @@ yy51:
|
||||
ZVAL_STRINGL(*rval, str, len, 1);
|
||||
return 1;
|
||||
}
|
||||
#line 1010 "ext/standard/var_unserializer.c"
|
||||
#line 1017 "ext/standard/var_unserializer.c"
|
||||
yy53:
|
||||
yych = *++YYCURSOR;
|
||||
switch (yych) {
|
||||
@@ -1130,7 +1137,7 @@ yy61:
|
||||
}
|
||||
yy63:
|
||||
++YYCURSOR;
|
||||
#line 515 "ext/standard/var_unserializer.re"
|
||||
#line 522 "ext/standard/var_unserializer.re"
|
||||
{
|
||||
#if SIZEOF_LONG == 4
|
||||
use_double:
|
||||
@@ -1140,7 +1147,7 @@ use_double:
|
||||
ZVAL_DOUBLE(*rval, zend_strtod((const char *)start + 2, NULL));
|
||||
return 1;
|
||||
}
|
||||
#line 1144 "ext/standard/var_unserializer.c"
|
||||
#line 1151 "ext/standard/var_unserializer.c"
|
||||
yy65:
|
||||
yych = *++YYCURSOR;
|
||||
switch (yych) {
|
||||
@@ -1242,7 +1249,7 @@ yy73:
|
||||
}
|
||||
yy74:
|
||||
++YYCURSOR;
|
||||
#line 500 "ext/standard/var_unserializer.re"
|
||||
#line 507 "ext/standard/var_unserializer.re"
|
||||
{
|
||||
*p = YYCURSOR;
|
||||
INIT_PZVAL(*rval);
|
||||
@@ -1257,7 +1264,7 @@ yy74:
|
||||
|
||||
return 1;
|
||||
}
|
||||
#line 1261 "ext/standard/var_unserializer.c"
|
||||
#line 1268 "ext/standard/var_unserializer.c"
|
||||
yy76:
|
||||
yych = *++YYCURSOR;
|
||||
switch (yych) {
|
||||
@@ -1316,7 +1323,7 @@ yy79:
|
||||
}
|
||||
yy81:
|
||||
++YYCURSOR;
|
||||
#line 473 "ext/standard/var_unserializer.re"
|
||||
#line 480 "ext/standard/var_unserializer.re"
|
||||
{
|
||||
#if SIZEOF_LONG == 4
|
||||
int digits = YYCURSOR - start - 3;
|
||||
@@ -1343,7 +1350,7 @@ yy81:
|
||||
ZVAL_LONG(*rval, parse_iv(start + 2));
|
||||
return 1;
|
||||
}
|
||||
#line 1347 "ext/standard/var_unserializer.c"
|
||||
#line 1354 "ext/standard/var_unserializer.c"
|
||||
yy83:
|
||||
yych = *++YYCURSOR;
|
||||
switch (yych) {
|
||||
@@ -1359,24 +1366,24 @@ yy84:
|
||||
}
|
||||
yy85:
|
||||
++YYCURSOR;
|
||||
#line 466 "ext/standard/var_unserializer.re"
|
||||
#line 473 "ext/standard/var_unserializer.re"
|
||||
{
|
||||
*p = YYCURSOR;
|
||||
INIT_PZVAL(*rval);
|
||||
ZVAL_BOOL(*rval, parse_iv(start + 2));
|
||||
return 1;
|
||||
}
|
||||
#line 1370 "ext/standard/var_unserializer.c"
|
||||
#line 1377 "ext/standard/var_unserializer.c"
|
||||
yy87:
|
||||
++YYCURSOR;
|
||||
#line 459 "ext/standard/var_unserializer.re"
|
||||
#line 466 "ext/standard/var_unserializer.re"
|
||||
{
|
||||
*p = YYCURSOR;
|
||||
INIT_PZVAL(*rval);
|
||||
ZVAL_NULL(*rval);
|
||||
return 1;
|
||||
}
|
||||
#line 1380 "ext/standard/var_unserializer.c"
|
||||
#line 1387 "ext/standard/var_unserializer.c"
|
||||
yy89:
|
||||
yych = *++YYCURSOR;
|
||||
switch (yych) {
|
||||
@@ -1429,7 +1436,7 @@ yy91:
|
||||
}
|
||||
yy93:
|
||||
++YYCURSOR;
|
||||
#line 436 "ext/standard/var_unserializer.re"
|
||||
#line 443 "ext/standard/var_unserializer.re"
|
||||
{
|
||||
long id;
|
||||
|
||||
@@ -1452,7 +1459,7 @@ yy93:
|
||||
|
||||
return 1;
|
||||
}
|
||||
#line 1456 "ext/standard/var_unserializer.c"
|
||||
#line 1463 "ext/standard/var_unserializer.c"
|
||||
yy95:
|
||||
yych = *++YYCURSOR;
|
||||
switch (yych) {
|
||||
@@ -1505,7 +1512,7 @@ yy97:
|
||||
}
|
||||
yy99:
|
||||
++YYCURSOR;
|
||||
#line 415 "ext/standard/var_unserializer.re"
|
||||
#line 422 "ext/standard/var_unserializer.re"
|
||||
{
|
||||
long id;
|
||||
|
||||
@@ -1526,9 +1533,9 @@ yy99:
|
||||
|
||||
return 1;
|
||||
}
|
||||
#line 1530 "ext/standard/var_unserializer.c"
|
||||
#line 1537 "ext/standard/var_unserializer.c"
|
||||
}
|
||||
#line 735 "ext/standard/var_unserializer.re"
|
||||
#line 742 "ext/standard/var_unserializer.re"
|
||||
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -268,7 +268,7 @@ static inline size_t parse_uiv(const unsigned char *p)
|
||||
#define UNSERIALIZE_PARAMETER zval **rval, const unsigned char **p, const unsigned char *max, php_unserialize_data_t *var_hash TSRMLS_DC
|
||||
#define UNSERIALIZE_PASSTHRU rval, p, max, var_hash TSRMLS_CC
|
||||
|
||||
static inline int process_nested_data(UNSERIALIZE_PARAMETER, HashTable *ht, long elements)
|
||||
static inline int process_nested_data(UNSERIALIZE_PARAMETER, HashTable *ht, long elements, int objprops)
|
||||
{
|
||||
while (elements-- > 0) {
|
||||
zval *key, *data, **old_data;
|
||||
@@ -297,7 +297,8 @@ static inline int process_nested_data(UNSERIALIZE_PARAMETER, HashTable *ht, long
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (Z_TYPE_P(key)) {
|
||||
if (!objprops) {
|
||||
switch (Z_TYPE_P(key)) {
|
||||
case IS_LONG:
|
||||
if (zend_hash_index_find(ht, Z_LVAL_P(key), (void **)&old_data)==SUCCESS) {
|
||||
var_push_dtor(var_hash, old_data);
|
||||
@@ -310,6 +311,12 @@ static inline int process_nested_data(UNSERIALIZE_PARAMETER, HashTable *ht, long
|
||||
}
|
||||
zend_symtable_update(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, &data, sizeof(data), NULL);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
/* object properties should include no integers */
|
||||
convert_to_string(key);
|
||||
zend_hash_update(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, &data,
|
||||
sizeof data, NULL);
|
||||
}
|
||||
|
||||
zval_dtor(key);
|
||||
@@ -377,7 +384,7 @@ static inline int object_common2(UNSERIALIZE_PARAMETER, long elements)
|
||||
zval *retval_ptr = NULL;
|
||||
zval fname;
|
||||
|
||||
if (!process_nested_data(UNSERIALIZE_PASSTHRU, Z_OBJPROP_PP(rval), elements)) {
|
||||
if (!process_nested_data(UNSERIALIZE_PASSTHRU, Z_OBJPROP_PP(rval), elements, 1)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -592,7 +599,7 @@ use_double:
|
||||
|
||||
array_init_size(*rval, elements);
|
||||
|
||||
if (!process_nested_data(UNSERIALIZE_PASSTHRU, Z_ARRVAL_PP(rval), elements)) {
|
||||
if (!process_nested_data(UNSERIALIZE_PASSTHRU, Z_ARRVAL_PP(rval), elements, 0)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user