Skip to content

Commit 8ca1313

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix out of bound writes to SafeArray data
2 parents 41996e8 + 42a2b04 commit 8ca1313

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

ext/com_dotnet/com_variant.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626

2727
/* create an automation SafeArray from a PHP array.
2828
* Only creates a single-dimensional array of variants.
29-
* The keys of the PHP hash MUST be numeric. If the array
30-
* is sparse, then the gaps will be filled with NULL variants */
29+
* The keys of the PHP hash MUST be numeric. */
3130
static void safe_array_from_zval(VARIANT *v, zval *z, int codepage)
3231
{
3332
SAFEARRAY *sa = NULL;
@@ -71,7 +70,9 @@ static void safe_array_from_zval(VARIANT *v, zval *z, int codepage)
7170
break;
7271
}
7372
zend_hash_get_current_key_ex(Z_ARRVAL_P(z), &strindex, &intindex, &pos);
74-
php_com_variant_from_zval(&va[intindex], item, codepage);
73+
if (intindex < bound.cElements) {
74+
php_com_variant_from_zval(&va[intindex], item, codepage);
75+
}
7576
}
7677

7778
/* Unlock it and stuff it into our variant */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Testing variant arrays
3+
--EXTENSIONS--
4+
com_dotnet
5+
--FILE--
6+
<?php
7+
$arrays = [
8+
"order" => [2 => 1, 1 => 2, 0 => 3],
9+
"off" => [2 => 1, 1 => 2, 3],
10+
"negative" => [-1 => 42],
11+
];
12+
foreach ($arrays as $desc => $array) {
13+
echo "-- $desc --\n";
14+
$v = new variant($array);
15+
foreach ($v as $val) {
16+
var_dump($val);
17+
}
18+
}
19+
?>
20+
--EXPECTF--
21+
-- order --
22+
int(3)
23+
int(2)
24+
int(1)
25+
-- off --
26+
NULL
27+
int(2)
28+
int(1)
29+
-- negative --
30+
%ANULL

0 commit comments

Comments
 (0)