From a30772d98825740a3f971961f9ceba410b3c5fad Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Tue, 14 Jun 2022 15:56:03 +0200 Subject: [PATCH] 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. --- ext/com_dotnet/com_handlers.c | 6 +++++- ext/com_dotnet/tests/gh8778.phpt | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 ext/com_dotnet/tests/gh8778.phpt diff --git a/ext/com_dotnet/com_handlers.c b/ext/com_dotnet/com_handlers.c index fb4af4efec2c4..4b8fd09a453fb 100644 --- a/ext/com_dotnet/com_handlers.c +++ b/ext/com_dotnet/com_handlers.c @@ -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; diff --git a/ext/com_dotnet/tests/gh8778.phpt b/ext/com_dotnet/tests/gh8778.phpt new file mode 100644 index 0000000000000..968804b7c5c81 --- /dev/null +++ b/ext/com_dotnet/tests/gh8778.phpt @@ -0,0 +1,18 @@ +--TEST-- +Bug GH-8778 (Integer arithmethic with large number variants fails) +--SKIPIF-- + +--FILE-- + +--EXPECT-- +int(4294967296) +int(4294967297)