diff options
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | Zend/zend_alloc.c | 13 | ||||
-rw-r--r-- | Zend/zend_multiply.h | 13 | ||||
-rw-r--r-- | Zend/zend_types.h | 14 |
4 files changed, 41 insertions, 0 deletions
@@ -43,6 +43,7 @@ PHP NEWS . Added ability to handle exceptions in destructors. (Marcus) - Improved PHP runtime speed and memory usage: + . Optimized ZEND_SIGNED_MULTIPLY_LONG() (Matt) . Removed direct executor recursion. (Dmitry) . Use fastcall calling convention in executor on x86. (Dmitry) . Use IS_CV for direct access to $this variable. (Dmitry) diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c index 856abc6711..67b415e056 100644 --- a/Zend/zend_alloc.c +++ b/Zend/zend_alloc.c @@ -2355,6 +2355,19 @@ static inline size_t safe_address(size_t nmemb, size_t size, size_t offset) return res; } +#elif SIZEOF_SIZE_T == 4 && defined(HAVE_ZEND_LONG64) + +static inline size_t safe_address(size_t nmemb, size_t size, size_t offset) +{ + zend_ulong64 res = (zend_ulong64)nmemb * (zend_ulong64)size + (zend_ulong64)offset; + + if (UNEXPECTED(res > (zend_ulong64)0xFFFFFFFFL)) { + zend_error_noreturn(E_ERROR, "Possible integer overflow in memory allocation (%zu * %zu + %zu)", nmemb, size, offset); + return 0; + } + return (size_t) res; +} + #else static inline size_t safe_address(size_t nmemb, size_t size, size_t offset) diff --git a/Zend/zend_multiply.h b/Zend/zend_multiply.h index 0fe9eeba20..8f5f03d70e 100644 --- a/Zend/zend_multiply.h +++ b/Zend/zend_multiply.h @@ -31,6 +31,19 @@ else (lval) = __tmpvar; \ } while (0) +#elif SIZEOF_LONG == 4 && defined(HAVE_ZEND_LONG64) + +#define ZEND_SIGNED_MULTIPLY_LONG(a, b, lval, dval, usedval) do { \ + zend_long64 __result = (zend_long64) (a) * (zend_long64) (b); \ + if (__result > LONG_MAX || __result < LONG_MIN) { \ + (dval) = (double) __result; \ + (usedval) = 1; \ + } else { \ + (lval) = (long) __result; \ + (usedval) = 0; \ + } \ +} while (0) + #else #define ZEND_SIGNED_MULTIPLY_LONG(a, b, lval, dval, usedval) do { \ diff --git a/Zend/zend_types.h b/Zend/zend_types.h index 66b328547b..9ea1c44f21 100644 --- a/Zend/zend_types.h +++ b/Zend/zend_types.h @@ -28,6 +28,20 @@ typedef unsigned int zend_uint; typedef unsigned long zend_ulong; typedef unsigned short zend_ushort; +#define HAVE_ZEND_LONG64 +#ifdef ZEND_WIN32 +typedef __int64 zend_long64; +typedef unsigned __int64 zend_ulong64; +#elif SIZEOF_LONG_LONG_INT == 8 +typedef long long int zend_long64; +typedef unsigned long long int zend_ulong64; +#elif SIZEOF_LONG_LONG == 8 +typedef long long zend_long64; +typedef unsigned long long zend_ulong64; +#else +# undef HAVE_ZEND_LONG64 +#endif + #ifdef _WIN64 typedef __int64 zend_intptr_t; typedef unsigned __int64 zend_uintptr_t; |