cvs: ZendEngine2(PHP_5_3) / zend.h zend_hash.h zend_operators.h /tests bug45877.phpt php-src NEWS

[email protected] ("Matt Wilmas") Wed, 18 Mar 2009 01:08:12 -0000
Newsgroups php.zend-engine.cvs
Message-ID <cvsmattwil1237338492@cvsserver>
mattwil		Wed Mar 18 01:08:12 2009 UTC

  Added files:                 (Branch: PHP_5_3)
    /ZendEngine2/tests	bug45877.phpt 

  Modified files:              
    /php-src	NEWS 
    /ZendEngine2	zend.h zend_hash.h zend_operators.h 
  Log:
  MFH: Fixed bug #45877 (Array key '2147483647' left as string)
  
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.965.2.520&r2=1.2027.2.547.2.965.2.521&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.965.2.520 php-src/NEWS:1.2027.2.547.2.965.2.521
--- php-src/NEWS:1.2027.2.547.2.965.2.520	Wed Mar 18 00:31:40 2009
+++ php-src/NEWS	Wed Mar 18 01:08:12 2009
@@ -40,6 +40,7 @@
 - Fixed bug #46347 (parse_ini_file() doesn't support * in keys). (Nuno)
 - Fixed bug #46048 (SimpleXML top-level @attributes not part of iterator).
   (David C.)
+- Fixed bug #45877 (Array key '2147483647' left as string). (Matt)
 - Fixed bug #45432 (PDO: persistent connection leak). (Felipe)
 - Fixed bug #43831 ($this gets mangled when extending PDO with persistent 
   connection). (Felipe)
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend.h?r1=1.293.2.11.2.9.2.32&r2=1.293.2.11.2.9.2.33&diff_format=u
Index: ZendEngine2/zend.h
diff -u ZendEngine2/zend.h:1.293.2.11.2.9.2.32 ZendEngine2/zend.h:1.293.2.11.2.9.2.33
--- ZendEngine2/zend.h:1.293.2.11.2.9.2.32	Wed Feb 18 10:55:08 2009
+++ ZendEngine2/zend.h	Wed Mar 18 01:08:12 2009
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend.h,v 1.293.2.11.2.9.2.32 2009/02/18 10:55:08 dmitry Exp $ */
+/* $Id: zend.h,v 1.293.2.11.2.9.2.33 2009/03/18 01:08:12 mattwil Exp $ */
 
 #ifndef ZEND_H
 #define ZEND_H
@@ -262,6 +262,18 @@
 #define LONG_MIN (- LONG_MAX - 1)
 #endif
 
+#if SIZEOF_LONG == 4
+#define MAX_LENGTH_OF_LONG 11
+static const char long_min_digits[] = "2147483648";
+#elif SIZEOF_LONG == 8
+#define MAX_LENGTH_OF_LONG 20
+static const char long_min_digits[] = "9223372036854775808";
+#else
+#error "Unknown SIZEOF_LONG"
+#endif
+
+#define MAX_LENGTH_OF_DOUBLE 32
+
 #undef SUCCESS
 #undef FAILURE
 #define SUCCESS 0
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_hash.h?r1=1.78.2.2.2.2.2.8&r2=1.78.2.2.2.2.2.9&diff_format=u
Index: ZendEngine2/zend_hash.h
diff -u ZendEngine2/zend_hash.h:1.78.2.2.2.2.2.8 ZendEngine2/zend_hash.h:1.78.2.2.2.2.2.9
--- ZendEngine2/zend_hash.h:1.78.2.2.2.2.2.8	Wed Dec 31 11:15:32 2008
+++ ZendEngine2/zend_hash.h	Wed Mar 18 01:08:12 2009
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_hash.h,v 1.78.2.2.2.2.2.8 2008/12/31 11:15:32 sebastian Exp $ */
+/* $Id: zend_hash.h,v 1.78.2.2.2.2.2.9 2009/03/18 01:08:12 mattwil Exp $ */
 
 #ifndef ZEND_HASH_H
 #define ZEND_HASH_H
@@ -313,9 +313,10 @@
 	}																					\
 	if ((*tmp>='0' && *tmp<='9')) do { /* possibly a numeric index */					\
 		const char *end=key+length-1;															\
-		long idx;																		\
+		long idx = end - tmp; /* temp var for remaining length (number of digits) */	\
 																						\
-		if (*tmp++=='0' && length>2) { /* don't accept numbers with leading zeros */	\
+		if (idx > MAX_LENGTH_OF_LONG - 1 || (*tmp++ == '0' && length > 2)) {			\
+			/* don't accept numbers too long or with leading zeros */					\
 			break;																		\
 		}																				\
 		while (tmp<end) {																\
@@ -325,17 +326,16 @@
 			tmp++;																		\
 		}																				\
 		if (tmp==end && *tmp=='\0') { /* a numeric index */								\
-			if (*key=='-') {															\
-				idx = strtol(key, NULL, 10);											\
-				if (idx!=LONG_MIN) {													\
-					return func;														\
-				}																		\
-			} else {																	\
-				idx = strtol(key, NULL, 10);											\
-				if (idx!=LONG_MAX) {													\
-					return func;														\
+			if (idx == MAX_LENGTH_OF_LONG - 1) {										\
+				int cmp = strcmp(end - (MAX_LENGTH_OF_LONG - 1), long_min_digits);		\
+																						\
+				if (!(cmp < 0 || (cmp == 0 && *key == '-'))) {							\
+					break;																\
 				}																		\
 			}																			\
+																						\
+			idx = strtol(key, NULL, 10);												\
+			return func;																\
 		}																				\
 	} while (0);																		\
 }
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_operators.h?r1=1.94.2.4.2.10.2.13&r2=1.94.2.4.2.10.2.14&diff_format=u
Index: ZendEngine2/zend_operators.h
diff -u ZendEngine2/zend_operators.h:1.94.2.4.2.10.2.13 ZendEngine2/zend_operators.h:1.94.2.4.2.10.2.14
--- ZendEngine2/zend_operators.h:1.94.2.4.2.10.2.13	Mon Jan  5 20:31:51 2009
+++ ZendEngine2/zend_operators.h	Wed Mar 18 01:08:12 2009
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_operators.h,v 1.94.2.4.2.10.2.13 2009/01/05 20:31:51 felipe Exp $ */
+/* $Id: zend_operators.h,v 1.94.2.4.2.10.2.14 2009/03/18 01:08:12 mattwil Exp $ */
 
 #ifndef ZEND_OPERATORS_H
 #define ZEND_OPERATORS_H
@@ -36,18 +36,6 @@
 #include "ext/bcmath/libbcmath/src/bcmath.h"
 #endif
 
-#if SIZEOF_LONG == 4
-#define MAX_LENGTH_OF_LONG 11
-static const char long_min_digits[] = "2147483648";
-#elif SIZEOF_LONG == 8
-#define MAX_LENGTH_OF_LONG 20
-static const char long_min_digits[] = "9223372036854775808";
-#else
-#error "Unknown SIZEOF_LONG"
-#endif
-
-#define MAX_LENGTH_OF_DOUBLE 32
-
 BEGIN_EXTERN_C()
 ZEND_API int add_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);
 ZEND_API int sub_function(zval *result, zval *op1, zval *op2 TSRMLS_DC);

http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/bug45877.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/bug45877.phpt
+++ ZendEngine2/tests/bug45877.phpt
--TEST--
Bug #45877 (Array key '2147483647' left as string)
--FILE--
<?php
$keys = array(PHP_INT_MAX,
	(string) PHP_INT_MAX,
	(string) (-PHP_INT_MAX - 1),
	-PHP_INT_MAX - 1,
	(string) (PHP_INT_MAX + 1));

var_dump(array_fill_keys($keys, 1));
?>
--EXPECTF--
array(3) {
  [%d7]=>
  int(1)
  [-%d8]=>
  int(1)
  [u"%d8"]=>
  int(1)
}