Skip to content

Commit 40f8010

Browse files
committed
Merge branch 'PHP-5.3' into PHP-5.4
* PHP-5.3: Fixed bug #62477 LimitIterator int overflow
2 parents 977ce78 + b383ddf commit 40f8010

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

ext/spl/spl_iterators.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1382,12 +1382,31 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
13821382
intern->dit_type = dit_type;
13831383
switch (dit_type) {
13841384
case DIT_LimitIterator: {
1385+
zval *tmp_offset, *tmp_count;
13851386
intern->u.limit.offset = 0; /* start at beginning */
13861387
intern->u.limit.count = -1; /* get all */
1387-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|ll", &zobject, ce_inner, &intern->u.limit.offset, &intern->u.limit.count) == FAILURE) {
1388+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|zz", &zobject, ce_inner, &tmp_offset, &tmp_count) == FAILURE) {
13881389
zend_restore_error_handling(&error_handling TSRMLS_CC);
13891390
return NULL;
13901391
}
1392+
if (tmp_offset && Z_TYPE_P(tmp_offset) != IS_NULL) {
1393+
if (Z_TYPE_P(tmp_offset) != IS_LONG) {
1394+
zend_throw_exception(spl_ce_OutOfRangeException, "offset param must be of type int", 0 TSRMLS_CC);
1395+
zend_restore_error_handling(&error_handling TSRMLS_CC);
1396+
return NULL;
1397+
} else {
1398+
intern->u.limit.offset = Z_LVAL_P(tmp_offset);
1399+
}
1400+
}
1401+
if (tmp_count && Z_TYPE_P(tmp_count) != IS_NULL) {
1402+
if (Z_TYPE_P(tmp_count) != IS_LONG) {
1403+
zend_throw_exception(spl_ce_OutOfRangeException, "count param must be of type int", 0 TSRMLS_CC);
1404+
zend_restore_error_handling(&error_handling TSRMLS_CC);
1405+
return NULL;
1406+
} else {
1407+
intern->u.limit.count = Z_LVAL_P(tmp_count);
1408+
}
1409+
}
13911410
if (intern->u.limit.offset < 0) {
13921411
zend_throw_exception(spl_ce_OutOfRangeException, "Parameter offset must be >= 0", 0 TSRMLS_CC);
13931412
zend_restore_error_handling(&error_handling TSRMLS_CC);

ext/spl/spl_iterators.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ typedef struct _spl_dual_it_object {
137137
uint str_key_len;
138138
ulong int_key;
139139
int key_type; /* HASH_KEY_IS_STRING or HASH_KEY_IS_LONG */
140-
int pos;
140+
long pos;
141141
} current;
142142
dual_it_type dit_type;
143143
union {

ext/spl/tests/bug62477_1.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Bug #62477 LimitIterator int overflow when float is passed (1)
3+
--FILE--
4+
<?php
5+
6+
$it = new LimitIterator(new ArrayIterator(array(42)), 10000000000000000000);
7+
--EXPECTF--
8+
Fatal error: Uncaught exception 'OutOfRangeException' with message 'offset param must be of type int' in %sbug62477_1.php:%d
9+
Stack trace:
10+
#0 %sbug62477_1.php(%d): LimitIterator->__construct(Object(ArrayIterator), %f)
11+
#1 {main}
12+
thrown in %sbug62477_1.php on line %d

ext/spl/tests/bug62477_2.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Bug #62477 LimitIterator int overflow when float is passed (2)
3+
--FILE--
4+
<?php
5+
6+
$it = new LimitIterator(new ArrayIterator(array(42)), 0, 10000000000000000000);
7+
--EXPECTF--
8+
Fatal error: Uncaught exception 'OutOfRangeException' with message 'count param must be of type int' in %sbug62477_2.php:%d
9+
Stack trace:
10+
#0 %sbug62477_2.php(%d): LimitIterator->__construct(Object(ArrayIterator), 0, %f)
11+
#1 {main}
12+
thrown in %sbug62477_2.php on line %d

0 commit comments

Comments
 (0)