Skip to content

Commit f649ade

Browse files
committed
Fix #79248: Traversing empty VT_ARRAY throws com_exception
If the `VT_ARRAY` is empty, i.e. its upperbound is less than its lower bound, we must not call `php_com_safearray_get_elem()`, because that function throws in this case.
1 parent 674d44a commit f649ade

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ PHP NEWS
77
(cmb)
88
. Fixed bug #79242 (COM error constants don't match com_exception codes on
99
x86). (cmb)
10+
. Fixed bug #79248 (Traversing empty VT_ARRAY throws com_exception). (cmb)
1011

1112
- PCRE:
1213
. Fixed bug #79188 (Memory corruption in preg_replace/preg_replace_callback

ext/com_dotnet/com_iterator.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ zend_object_iterator *php_com_iter_get(zend_class_entry *ce, zval *object, int b
187187
SafeArrayGetUBound(V_ARRAY(&I->safe_array), 1, &I->sa_max);
188188

189189
/* pre-fetch the element */
190-
if (php_com_safearray_get_elem(&I->safe_array, &I->v, bound)) {
190+
if (I->sa_max >= bound && php_com_safearray_get_elem(&I->safe_array, &I->v, bound)) {
191191
I->key = bound;
192192
ZVAL_NULL(&ptr);
193193
php_com_zval_from_variant(&ptr, &I->v, I->code_page);

ext/com_dotnet/tests/bug79248.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Bug #79248 (Traversing empty VT_ARRAY throws com_exception)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('com_dotnet')) die('skip com_dotnet extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
$v = new variant([], VT_ARRAY);
10+
foreach ($v as $el) {
11+
var_dump($el);
12+
}
13+
echo "done\n";
14+
?>
15+
--EXPECT--
16+
done

0 commit comments

Comments
 (0)