diff options
| author | Matt Wilmas <mattwil@php.net> | 2009-03-18 01:08:12 +0000 |
|---|---|---|
| committer | Matt Wilmas <mattwil@php.net> | 2009-03-18 01:08:12 +0000 |
| commit | 6bb0ac971265862105dac55e305ea0a897edbd4b (patch) | |
| tree | e30da5039c6a9cd5b1890ee4ae2a80ebdbd1e4ba | |
| parent | 30d058488eb25b30c0097cbe6781ccc49e9fbf37 (diff) | |
| download | php-git-6bb0ac971265862105dac55e305ea0a897edbd4b.tar.gz | |
MFH: Fixed bug #45877 (Array key '2147483647' left as string)
| -rw-r--r-- | NEWS | 1 | ||||
| -rw-r--r-- | Zend/tests/bug45877.phpt | 21 | ||||
| -rw-r--r-- | Zend/zend.h | 12 | ||||
| -rw-r--r-- | Zend/zend_hash.h | 22 | ||||
| -rw-r--r-- | Zend/zend_operators.h | 12 |
5 files changed, 45 insertions, 23 deletions
@@ -40,6 +40,7 @@ PHP NEWS - 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) diff --git a/Zend/tests/bug45877.phpt b/Zend/tests/bug45877.phpt new file mode 100644 index 0000000000..741bd536f3 --- /dev/null +++ b/Zend/tests/bug45877.phpt @@ -0,0 +1,21 @@ +--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) + ["%d8"]=> + int(1) +} diff --git a/Zend/zend.h b/Zend/zend.h index c270f88740..ed7cc78904 100644 --- a/Zend/zend.h +++ b/Zend/zend.h @@ -262,6 +262,18 @@ char *alloca (); #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 diff --git a/Zend/zend_hash.h b/Zend/zend_hash.h index cbee0d653a..698fe4a548 100644 --- a/Zend/zend_hash.h +++ b/Zend/zend_hash.h @@ -313,9 +313,10 @@ END_EXTERN_C() } \ 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 @@ END_EXTERN_C() 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); \ } diff --git a/Zend/zend_operators.h b/Zend/zend_operators.h index 19f3a32461..f549dad1b5 100644 --- a/Zend/zend_operators.h +++ b/Zend/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); |
