php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51119 Incorrect exception message in LimitIterator
Submitted: 2010-02-22 21:24 UTC Modified: 2010-02-23 00:06 UTC
From: salathe@php.net Assigned:
Status: Closed Package: SPL related
PHP Version: 5.3.2RC2 OS: OS X
Private report: No CVE-ID: None
 [2010-02-22 21:24 UTC] salathe@php.net
Description:
------------
The lower bound of the offset parameter for the FilterIterator is zero (no offset). When an offset less than zero is given, an OutOfBoundsException is thrown, incorrectly stating, "Parameter offset must be > 0".

Reproduce code:
---------------
<?php

$ait = new ArrayIterator(array('a', 'b', 'c'));

try {
    $lit = new LimitIterator($ait, 0);
    echo "OK\n";
} catch (OutOfRangeException $e) {
    echo $e->getMessage() . "\n";
}

try {
    $lit = new LimitIterator($ait, -1);
    echo "OK\n";
} catch (OutOfRangeException $e) {
    echo $e->getMessage() . "\n";
}


Expected result:
----------------
OK
Parameter offset must be >= 0

Actual result:
--------------
OK
Parameter offset must be > 0

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-02-22 21:26 UTC] salathe@php.net
The tiny, tiny patch (against trunk) would be:

Index: spl_iterators.c
===================================================================
--- spl_iterators.c	(revision 295379)
+++ spl_iterators.c	(working copy)
@@ -1321,7 +1321,7 @@
 				return NULL;
 			}
 			if (intern->u.limit.offset < 0) {
-				zend_throw_exception(spl_ce_OutOfRangeException, "Parameter offset must be > 0", 0 TSRMLS_CC);
+				zend_throw_exception(spl_ce_OutOfRangeException, "Parameter offset must be >= 0", 0 TSRMLS_CC);
 				zend_restore_error_handling(&error_handling TSRMLS_CC);
 				return NULL;
 			}

 [2010-02-22 21:59 UTC] salathe@php.net
Oops typo in the original message: I said "FilterIterator" in place of, the correct class, LimitIterator.
 [2010-02-22 23:55 UTC] svn@php.net
Automatic comment from SVN on behalf of salathe
Revision: http://svn.php.net/viewvc/?view=revision&revision=295391
Log: Corrected typo in LimitIterator offset exception. Fixes #51119
 [2010-02-23 00:06 UTC] salathe@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 19:01:33 2024 UTC