mattwil         Tue Mar 17 22:04:10 2009 UTC

  Added files:                 (Branch: PHP_5_3)
    /php-src/ext/standard/tests/serialize       bug46882.phpt 

  Modified files:              
    /php-src/ext/standard       var_unserializer.c var_unserializer.re 
  Log:
  MFH: Fixed bug #46882 (Serialize / Unserialize misbehaviour under OS with 
different bit numbers)
  
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/var_unserializer.c?r1=1.70.2.4.2.7.2.8&r2=1.70.2.4.2.7.2.9&diff_format=u
Index: php-src/ext/standard/var_unserializer.c
diff -u php-src/ext/standard/var_unserializer.c:1.70.2.4.2.7.2.8 
php-src/ext/standard/var_unserializer.c:1.70.2.4.2.7.2.9
--- php-src/ext/standard/var_unserializer.c:1.70.2.4.2.7.2.8    Tue Nov  4 
15:58:55 2008
+++ php-src/ext/standard/var_unserializer.c     Tue Mar 17 22:04:10 2009
@@ -1,4 +1,4 @@
-/* Generated by re2c 0.13.6.dev on Tue Nov  4 01:37:59 2008 */
+/* Generated by re2c 0.13.5 on Tue Mar 17 15:55:10 2009 */
 #line 1 "ext/standard/var_unserializer.re"
 /*
   +----------------------------------------------------------------------+
@@ -18,7 +18,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: var_unserializer.c,v 1.70.2.4.2.7.2.8 2008/11/04 15:58:55 helly Exp $ 
*/
+/* $Id: var_unserializer.c,v 1.70.2.4.2.7.2.9 2009/03/17 22:04:10 mattwil Exp 
$ */
 
 #include "php.h"
 #include "ext/standard/php_var.h"
@@ -456,7 +456,7 @@
        yych = *(YYMARKER = ++YYCURSOR);
        if (yych == ':') goto yy95;
 yy3:
-#line 699 "ext/standard/var_unserializer.re"
+#line 722 "ext/standard/var_unserializer.re"
        { return 0; }
 #line 462 "ext/standard/var_unserializer.c"
 yy4:
@@ -501,7 +501,7 @@
        goto yy3;
 yy14:
        ++YYCURSOR;
-#line 693 "ext/standard/var_unserializer.re"
+#line 716 "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");
@@ -537,7 +537,7 @@
        yych = *++YYCURSOR;
        if (yych != '"') goto yy18;
        ++YYCURSOR;
-#line 576 "ext/standard/var_unserializer.re"
+#line 599 "ext/standard/var_unserializer.re"
        {
        size_t len, len2, len3, maxlen;
        long elements;
@@ -679,7 +679,7 @@
        yych = *++YYCURSOR;
        if (yych != '"') goto yy18;
        ++YYCURSOR;
-#line 568 "ext/standard/var_unserializer.re"
+#line 591 "ext/standard/var_unserializer.re"
        {
 
        INIT_PZVAL(*rval);
@@ -708,7 +708,7 @@
        yych = *++YYCURSOR;
        if (yych != '{') goto yy18;
        ++YYCURSOR;
-#line 548 "ext/standard/var_unserializer.re"
+#line 571 "ext/standard/var_unserializer.re"
        {
        long elements = parse_iv(start + 2);
        /* use iv() not uiv() in order to check data range */
@@ -749,7 +749,7 @@
        yych = *++YYCURSOR;
        if (yych != '"') goto yy18;
        ++YYCURSOR;
-#line 519 "ext/standard/var_unserializer.re"
+#line 542 "ext/standard/var_unserializer.re"
        {
        size_t len, maxlen;
        char *str;
@@ -799,7 +799,7 @@
        yych = *++YYCURSOR;
        if (yych != '"') goto yy18;
        ++YYCURSOR;
-#line 491 "ext/standard/var_unserializer.re"
+#line 514 "ext/standard/var_unserializer.re"
        {
        size_t len, maxlen;
        char *str;
@@ -915,14 +915,17 @@
        }
 yy63:
        ++YYCURSOR;
-#line 484 "ext/standard/var_unserializer.re"
+#line 504 "ext/standard/var_unserializer.re"
        {
+#if SIZEOF_LONG == 4
+use_double:
+#endif
        *p = YYCURSOR;
        INIT_PZVAL(*rval);
        ZVAL_DOUBLE(*rval, zend_strtod((const char *)start + 2, NULL));
        return 1;
 }
-#line 926 "ext/standard/var_unserializer.c"
+#line 929 "ext/standard/var_unserializer.c"
 yy65:
        yych = *++YYCURSOR;
        if (yych <= ',') {
@@ -981,7 +984,7 @@
        yych = *++YYCURSOR;
        if (yych != ';') goto yy18;
        ++YYCURSOR;
-#line 469 "ext/standard/var_unserializer.re"
+#line 489 "ext/standard/var_unserializer.re"
        {
        *p = YYCURSOR;
        INIT_PZVAL(*rval);
@@ -996,7 +999,7 @@
 
        return 1;
 }
-#line 1000 "ext/standard/var_unserializer.c"
+#line 1003 "ext/standard/var_unserializer.c"
 yy76:
        yych = *++YYCURSOR;
        if (yych == 'N') goto yy73;
@@ -1025,12 +1028,32 @@
        ++YYCURSOR;
 #line 462 "ext/standard/var_unserializer.re"
        {
+#if SIZEOF_LONG == 4
+       int digits = YYCURSOR - start - 3;
+
+       if (start[2] == '-' || start[2] == '+') {
+               digits--;
+       }
+
+       /* Use double for large long values that were serialized on a 64-bit 
system */
+       if (digits >= MAX_LENGTH_OF_LONG - 1) {
+               if (digits == MAX_LENGTH_OF_LONG - 1) {
+                       int cmp = strncmp(YYCURSOR - MAX_LENGTH_OF_LONG, 
long_min_digits, MAX_LENGTH_OF_LONG - 1);
+
+                       if (!(cmp < 0 || (cmp == 0 && start[2] == '-'))) {
+                               goto use_double;
+                       }
+               } else {
+                       goto use_double;
+               }
+       }
+#endif
        *p = YYCURSOR;
        INIT_PZVAL(*rval);
        ZVAL_LONG(*rval, parse_iv(start + 2));
        return 1;
 }
-#line 1034 "ext/standard/var_unserializer.c"
+#line 1057 "ext/standard/var_unserializer.c"
 yy83:
        yych = *++YYCURSOR;
        if (yych <= '/') goto yy18;
@@ -1045,7 +1068,7 @@
        ZVAL_BOOL(*rval, parse_iv(start + 2));
        return 1;
 }
-#line 1049 "ext/standard/var_unserializer.c"
+#line 1072 "ext/standard/var_unserializer.c"
 yy87:
        ++YYCURSOR;
 #line 448 "ext/standard/var_unserializer.re"
@@ -1055,7 +1078,7 @@
        ZVAL_NULL(*rval);
        return 1;
 }
-#line 1059 "ext/standard/var_unserializer.c"
+#line 1082 "ext/standard/var_unserializer.c"
 yy89:
        yych = *++YYCURSOR;
        if (yych <= ',') {
@@ -1101,7 +1124,7 @@
        
        return 1;
 }
-#line 1105 "ext/standard/var_unserializer.c"
+#line 1128 "ext/standard/var_unserializer.c"
 yy95:
        yych = *++YYCURSOR;
        if (yych <= ',') {
@@ -1145,9 +1168,9 @@
        
        return 1;
 }
-#line 1149 "ext/standard/var_unserializer.c"
+#line 1172 "ext/standard/var_unserializer.c"
 }
-#line 701 "ext/standard/var_unserializer.re"
+#line 724 "ext/standard/var_unserializer.re"
 
 
        return 0;
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/var_unserializer.re?r1=1.52.2.2.2.6.2.7&r2=1.52.2.2.2.6.2.8&diff_format=u
Index: php-src/ext/standard/var_unserializer.re
diff -u php-src/ext/standard/var_unserializer.re:1.52.2.2.2.6.2.7 
php-src/ext/standard/var_unserializer.re:1.52.2.2.2.6.2.8
--- php-src/ext/standard/var_unserializer.re:1.52.2.2.2.6.2.7   Tue Nov  4 
15:58:55 2008
+++ php-src/ext/standard/var_unserializer.re    Tue Mar 17 22:04:10 2009
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: var_unserializer.re,v 1.52.2.2.2.6.2.7 2008/11/04 15:58:55 helly Exp $ 
*/
+/* $Id: var_unserializer.re,v 1.52.2.2.2.6.2.8 2009/03/17 22:04:10 mattwil Exp 
$ */
 
 #include "php.h"
 #include "ext/standard/php_var.h"
@@ -460,6 +460,26 @@
 }
 
 "i:" iv ";"    {
+#if SIZEOF_LONG == 4
+       int digits = YYCURSOR - start - 3;
+
+       if (start[2] == '-' || start[2] == '+') {
+               digits--;
+       }
+
+       /* Use double for large long values that were serialized on a 64-bit 
system */
+       if (digits >= MAX_LENGTH_OF_LONG - 1) {
+               if (digits == MAX_LENGTH_OF_LONG - 1) {
+                       int cmp = strncmp(YYCURSOR - MAX_LENGTH_OF_LONG, 
long_min_digits, MAX_LENGTH_OF_LONG - 1);
+
+                       if (!(cmp < 0 || (cmp == 0 && start[2] == '-'))) {
+                               goto use_double;
+                       }
+               } else {
+                       goto use_double;
+               }
+       }
+#endif
        *p = YYCURSOR;
        INIT_PZVAL(*rval);
        ZVAL_LONG(*rval, parse_iv(start + 2));
@@ -482,6 +502,9 @@
 }
 
 "d:" (iv | nv | nvexp) ";"     {
+#if SIZEOF_LONG == 4
+use_double:
+#endif
        *p = YYCURSOR;
        INIT_PZVAL(*rval);
        ZVAL_DOUBLE(*rval, zend_strtod((const char *)start + 2, NULL));

http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/serialize/bug46882.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/serialize/bug46882.phpt
+++ php-src/ext/standard/tests/serialize/bug46882.phpt
--TEST--
Bug #46882 (Serialize / Unserialize misbehaviour under OS with different bit 
numbers)
--FILE--
<?php
var_dump(unserialize('i:5000000000;') == 5000000000);
?>
--EXPECT--
bool(true)



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to