summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStanislav Malyshev <stas@php.net>2015-10-18 17:17:55 -0700
committerStanislav Malyshev <stas@php.net>2015-10-18 17:17:55 -0700
commit0b35e0c5a120c9ff98dad7e44259f26ca828a8e4 (patch)
tree904b6446ad8fa7da0715d6bd52f4adeb259564f0
parent73384728cadfc28ae6c621636de25fdada464e5b (diff)
parent368d3ff0d95c79ffdf042fb685bda703c7cb5c12 (diff)
downloadphp-git-0b35e0c5a120c9ff98dad7e44259f26ca828a8e4.tar.gz
Merge branch 'pull-request/1535' into PHP-5.6
* pull-request/1535: Bug #70561: Fix DirectoryIterator to throw OutOfBoundsException
-rw-r--r--ext/spl/spl_directory.c3
-rw-r--r--ext/spl/tests/bug70561.phpt23
-rw-r--r--ext/spl/tests/dit_006.phpt12
3 files changed, 32 insertions, 6 deletions
diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c
index 1d75138b48..7fb4ecd147 100644
--- a/ext/spl/spl_directory.c
+++ b/ext/spl/spl_directory.c
@@ -845,7 +845,8 @@ SPL_METHOD(DirectoryIterator, seek)
retval = NULL;
}
if (!valid) {
- break;
+ zend_throw_exception_ex(spl_ce_OutOfBoundsException, 0 TSRMLS_CC, "Seek position %ld is out of range", pos);
+ return;
}
zend_call_method_with_0_params(&this_ptr, Z_OBJCE_P(getThis()), &intern->u.dir.func_next, "next", &retval);
if (retval) {
diff --git a/ext/spl/tests/bug70561.phpt b/ext/spl/tests/bug70561.phpt
new file mode 100644
index 0000000000..c6c229ad89
--- /dev/null
+++ b/ext/spl/tests/bug70561.phpt
@@ -0,0 +1,23 @@
+--TEST--
+Bug #70561 (DirectoryIterator::seek should throw OutOfBoundsException)
+--FILE--
+<?php
+$di = new DirectoryIterator(__DIR__ . '/..');
+
+$cnt = 0;
+$di->rewind();
+while ($di->valid()) {
+ $cnt++;
+ $di->next();
+}
+
+try {
+ $di->seek($cnt+1);
+} catch (OutOfBoundsException $ex) {
+ echo $ex->getMessage() . PHP_EOL;
+}
+echo "Is valid? " . (int) $di->valid() . PHP_EOL;
+?>
+--EXPECTF--
+Seek position %d is out of range
+Is valid? 0
diff --git a/ext/spl/tests/dit_006.phpt b/ext/spl/tests/dit_006.phpt
index 9edbb9f157..ed1ceffc05 100644
--- a/ext/spl/tests/dit_006.phpt
+++ b/ext/spl/tests/dit_006.phpt
@@ -30,11 +30,12 @@ while ($di->valid()) {
echo "Without seek we get $o\n";
-$p = 0;
-$di->seek($o+1);
-while ($di->valid()) {
- $p++;
- $di->next();
+try {
+ $p = 0;
+ $di->seek($o+1);
+ $p = 1;
+} catch (\OutOfBoundsException $ex) {
+ echo $ex->getMessage() . PHP_EOL;
}
var_dump($n !== $m, $m === $o, $p === 0);
@@ -44,6 +45,7 @@ var_dump($n !== $m, $m === $o, $p === 0);
With seek(2) we get %d
With seek(0) we get %d
Without seek we get %d
+Seek position %d is out of range
bool(true)
bool(true)
bool(true)