mirror of
https://github.com/php/php-src.git
synced 2024-11-27 20:03:40 +08:00
MFH: Fixed bug #45877 (Array key '2147483647' left as string)
This commit is contained in:
parent
30d058488e
commit
6bb0ac9712
1
NEWS
1
NEWS
@ -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)
|
||||
|
21
Zend/tests/bug45877.phpt
Normal file
21
Zend/tests/bug45877.phpt
Normal file
@ -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)
|
||||
}
|
12
Zend/zend.h
12
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
|
||||
|
@ -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); \
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user