Skip to content

Commit

Permalink
Fix GH-8778: Integer arithmethic with large number variants fails
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cmb69 committed Jun 18, 2022
1 parent d84b972 commit 651e0cc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
4 changes: 4 additions & 0 deletions NEWS
Expand Up @@ -2,6 +2,10 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? 2022, PHP 8.0.21

- COM:
. Fixed bug GH-8778 (Integer arithmethic with large number variants fails).
(cmb)

- Curl:
. Fixed CURLOPT_TLSAUTH_TYPE is not treated as a string option. (Pierrick)

Expand Down
6 changes: 5 additions & 1 deletion ext/com_dotnet/com_handlers.c
Expand Up @@ -453,7 +453,11 @@ static int com_object_cast(zend_object *readobj, zval *writeobj, int type)
switch(type) {
case IS_LONG:
case _IS_NUMBER:
vt = VT_INT;
#if SIZEOF_ZEND_LONG == 4
vt = VT_I4;
#else
vt = VT_I8;
#endif
break;
case IS_DOUBLE:
vt = VT_R8;
Expand Down
18 changes: 18 additions & 0 deletions ext/com_dotnet/tests/gh8778.phpt
@@ -0,0 +1,18 @@
--TEST--
Bug GH-8778 (Integer arithmethic with large number variants fails)
--SKIPIF--
<?php
if (!extension_loaded("com_dotnet")) die("skip com_dotnet extension not available");
if (PHP_INT_SIZE < 8) die("skip for 64bit only");
?>
--FILE--
<?php
$int = 0x100000000;
var_dump(
$int,
new variant($int) + 1
);
?>
--EXPECT--
int(4294967296)
int(4294967297)

0 comments on commit 651e0cc

Please sign in to comment.