|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-08-09 05:30 UTC] frederic dot lecointre at burnweb dot net
Description: ------------ ArrayIterator::seek do nothing in this code and we can set an out of bounds argument. Reproduce code: --------------- <?php $myIt = new ArrayIterator(range( 0, 50)); $myIt->seek(20); echo $myIt->current(), "\n"; // out: 1 expected 20 $myIt->seek(5000); // ? out of bounds but no error or Exception ?> PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 17:00:01 2025 UTC |
fixed 1) output from Reproduce code: 20 -> expected and correct Warning: ArrayIterator::seek(): out of bounds in /root/bug_ArrayIterator_seek.psh on line 9 -> throw E_WARNING 2) code fix _________________________ /* {{{ proto void ArrayIterator::seek(int $position) Seek to position. */ SPL_METHOD(Array, seek) { long 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); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &position) == FAILURE) { return; } if (!aht) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside object and is no longer an array"); return; } /*-----start fix Bug #2091 Package: SPL Bug #2091 ArrayIterator::seek() do nothing ArrayIterator::seek do nothing in this code and we can set an out of bounds argument */ /* fix can pass out of bound argument */ if( zend_hash_num_elements(aht) > position){ zend_hash_internal_pointer_reset_ex(aht, &intern->pos); while (position-- > 0 && (spl_array_next(intern TSRMLS_CC) == SUCCESS)); /* fix seek do nothing */ } else{ php_error_docref(NULL TSRMLS_CC, E_WARNING, "out of bounds"); /* throw exception or error E_NOTICE, E_WARNING, E_ERROR ??? */ return; } /*-----end fix Bug #2091*/ } /* }}} */ ____________________________