From: Marcus Boerger Date: Tue, 1 Mar 2005 10:06:11 +0000 (+0000) Subject: - Fix #32130 (ArrayIterator::seek() does not throw an Exception on invalid index) X-Git-Tag: RELEASE_0_3~115 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=90012803875e2af54cba52cb769bf3e5e9128dd0;p=php - Fix #32130 (ArrayIterator::seek() does not throw an Exception on invalid index) --- diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index e19d45fadc..65fac7b84d 100755 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -726,10 +726,11 @@ SPL_METHOD(Array, rewind) Seek to position. */ SPL_METHOD(Array, seek) { - long position; + long opos, position; zval *object = getThis(); spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); HashTable *aht = HASH_OF(intern->array); + int result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &position) == FAILURE) { return; @@ -742,7 +743,17 @@ SPL_METHOD(Array, seek) zend_hash_internal_pointer_reset_ex(aht, &intern->pos); - while (position-- > 0 && spl_array_next(intern TSRMLS_CC) == SUCCESS); + opos = position; + while (position-- > 0 && (result = spl_array_next(intern TSRMLS_CC)) == SUCCESS); + + if (intern->pos && intern->is_ref && spl_hash_verify_pos(intern TSRMLS_CC) == FAILURE) { + /* fail */ + } else { + if (zend_hash_has_more_elements_ex(aht, &intern->pos) == SUCCESS) { + return; /* ok */ + } + } + zend_throw_exception_ex(spl_ce_OutOfBoundsException, 0 TSRMLS_CC, "Seek position %ld is out of range", opos); } /* }}} */ int spl_array_object_count_elements(zval *object, long *count TSRMLS_DC) /* {{{ */