Skip to content

Commit 651e0cc

Browse files
committed
Fix GH-8778: Integer arithmethic with large number variants fails
When casting a `variant` to `int`, we need to heed the proper `zval` type, which is an signed 64bit integer on x64, while `VT_INT` is only a signed 32bit integer. Closes GH-8779.
1 parent d84b972 commit 651e0cc

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? 2022, PHP 8.0.21
44

5+
- COM:
6+
. Fixed bug GH-8778 (Integer arithmethic with large number variants fails).
7+
(cmb)
8+
59
- Curl:
610
. Fixed CURLOPT_TLSAUTH_TYPE is not treated as a string option. (Pierrick)
711

ext/com_dotnet/com_handlers.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,11 @@ static int com_object_cast(zend_object *readobj, zval *writeobj, int type)
453453
switch(type) {
454454
case IS_LONG:
455455
case _IS_NUMBER:
456-
vt = VT_INT;
456+
#if SIZEOF_ZEND_LONG == 4
457+
vt = VT_I4;
458+
#else
459+
vt = VT_I8;
460+
#endif
457461
break;
458462
case IS_DOUBLE:
459463
vt = VT_R8;

ext/com_dotnet/tests/gh8778.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Bug GH-8778 (Integer arithmethic with large number variants fails)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded("com_dotnet")) die("skip com_dotnet extension not available");
6+
if (PHP_INT_SIZE < 8) die("skip for 64bit only");
7+
?>
8+
--FILE--
9+
<?php
10+
$int = 0x100000000;
11+
var_dump(
12+
$int,
13+
new variant($int) + 1
14+
);
15+
?>
16+
--EXPECT--
17+
int(4294967296)
18+
int(4294967297)

0 commit comments

Comments
 (0)