spl_dual_it_free(intern TSRMLS_CC);
if (!check_more || spl_dual_it_valid(intern TSRMLS_CC) == SUCCESS) {
intern->inner.iterator->funcs->get_current_data(intern->inner.iterator, &data TSRMLS_CC);
- intern->current.data = *data;
- Z_ADDREF_P(intern->current.data);
+ if (data && *data) {
+ intern->current.data = *data;
+ Z_ADDREF_P(intern->current.data);
+ }
if (intern->inner.iterator->funcs->get_current_key) {
intern->current.key_type = intern->inner.iterator->funcs->get_current_key(intern->inner.iterator, &intern->current.str_key, &intern->current.str_key_len, &intern->current.int_key TSRMLS_CC);
} else {
intern->current.key_type = HASH_KEY_IS_LONG;
intern->current.int_key = intern->current.pos;
}
- return SUCCESS;
+ return EG(exception) ? FAILURE : SUCCESS;
}
return FAILURE;
}
--- /dev/null
+--TEST--
+Bug #42703 (Exception raised in an iterator::current() causes segfault in FilterIterator)
+--FILE--
+<?php
+class BlaIterator implements Iterator
+{
+ public function rewind() { }
+
+ public function next() { }
+
+ public function valid() {
+ return true;
+ }
+
+ public function current()
+ {
+ throw new Exception('boo');
+ }
+
+ public function key() { }
+}
+
+$it = new BlaIterator();
+$itit = new IteratorIterator($it);
+
+try {
+ foreach($itit as $key => $value) {
+ echo $key, $value;
+ }
+}
+catch (Exception $e) {
+ var_dump($e->getMessage());
+}
+
+var_dump($itit->current());
+var_dump($itit->key());
+?>
+--EXPECTF--
+string(3) "boo"
+NULL
+NULL