Commit eb25d512886 for php
commit eb25d512886a2cde1628b36b6c34b61d26aa8038
Author: Marc Bennewitz <marc-mabe@users.noreply.github.com>
Date: Fri Nov 20 11:33:44 2026 +0100
Add ZEND_IN_RANGE_OF() and deprecate the zend_long/size_t vs. int range check macros (#23688)
* Add ZEND_IN_RANGE_OF() for range checks of any integer type
The existing range check macros each cover one pair of types, zend_long or
size_t against int or unsigned int, so a caller narrowing into a DWORD, an
uint32_t or an unsigned long has to pick the closest one and rely on the two
types being of the same width.
ZEND_IN_RANGE_OF(x, T) tells whether the value of the integer expression x
is representable in the integer type T, for any integer x and T not wider
than intmax_t, signed or unsigned. x is evaluated exactly once. In C it
dispatches on the promoted type of x with _Generic; C++ has no _Generic, so
there a function template deduces the type of x instead, which ext/intl
needs. Both call the same inline functions doing the comparison in intmax_t
or uintmax_t, so it behaves the same in C and C++, including not being a
constant expression in either.
Anything that is not an integer type, or is wider than intmax_t, fails to
compile instead of silently truncating.
ZEND_TYPE_MIN(T) and ZEND_TYPE_MAX(T), which it compares against, are
public as well: the limits of any such integer type T as integer constant
expressions, for types without a constant of their own such as time_t.
* Use ZEND_IN_RANGE_OF() for the range checks of the old macros
Move every caller of ZEND_LONG_INT_OVFL(), ZEND_LONG_INT_UDFL(),
ZEND_LONG_EXCEEDS_INT(), ZEND_LONG_UINT_OVFL(), ZEND_SIZE_T_INT_OVFL() and
ZEND_SIZE_T_UINT_OVFL() to ZEND_IN_RANGE_OF(). The old macros stay as they
are for code outside php-src.
Where the value is narrowed into another type than the one the old macro
checked, check that type instead: a DWORD for the codepages in win32, whose
messages now print MAXDWORD, the uint32_t the phar timestamp is stored in, and
an int32_t where intl passes the value on to ICU and where cal_to_jd() limits
the day, as their messages already say.
onig_set_retry_limit_in_match_of_match_param() takes an unsigned long, so
mbstring.regex_retry_limit is checked against that now. On LP64 a limit
beyond the range of an unsigned int is passed on instead of being dropped in
favour of oniguruma's default.
Callers which deliberately leave the lower bound open keep doing so:
bcmath accepts any negative precision, and in spec mode the DOM character
data methods convert a negative offset or count as an unsigned long.
* Deprecate the range check macros replaced by ZEND_IN_RANGE_OF()
ZEND_LONG_INT_OVFL(), ZEND_LONG_INT_UDFL(), ZEND_LONG_EXCEEDS_INT(),
ZEND_LONG_UINT_OVFL(), ZEND_SIZE_T_INT_OVFL() and ZEND_SIZE_T_UINT_OVFL()
have no callers left in php-src. They stay for code outside of it, with
their behaviour unchanged, but are deprecated in favour of
ZEND_IN_RANGE_OF().
C has no way to deprecate a macro, so each of them calls the empty function
_zend_deprecated_use_ZEND_IN_RANGE_OF_instead(), marked
ZEND_ATTRIBUTE_DEPRECATED, instead. Every use then raises
-Wdeprecated-declarations naming the replacement, and the compiler points at
the macro.
The flags ZEND_LONG_CAN_OVFL_INT, ZEND_LONG_CAN_OVFL_UINT and
ZEND_SIZE_T_CAN_OVFL_UINT only serve these macros and are deprecated as
well. Being only usable in #if, they can do so in a comment only.
zend_portability.h includes zend_range_check.h last now, after
ZEND_ATTRIBUTE_DEPRECATED is defined.
Where zend_long is not wider than an int, the deprecated
ZEND_LONG_UINT_OVFL() still rejects a negative value, matching the fix that
landed separately.
diff --git a/NEWS b/NEWS
index 8c8379da143..eaeb9894e2b 100644
--- a/NEWS
+++ b/NEWS
@@ -83,6 +83,8 @@ PHP NEWS
. Fixed bug GH-23958 (truncated encoding names resolving to full names). (Kamil Tekiela)
. Fixed stack overflow in mb_check_encoding() and mb_convert_encoding() with
deeply nested arrays. (Eyüp Can Akman)
+ . Fixed mbstring.regex_retry_limit above UINT_MAX being ignored.
+ (Marc Bennewitz)
- MySQLi:
. Fix GH-22854: Fixed failed assertion when accessing mysqli property after
diff --git a/UPGRADING.INTERNALS b/UPGRADING.INTERNALS
index 7b9f6bdf337..5d1864f3d6a 100644
--- a/UPGRADING.INTERNALS
+++ b/UPGRADING.INTERNALS
@@ -77,6 +77,14 @@ PHP 8.7 INTERNALS UPGRADE NOTES
scheduled restart has been carried out and the SHM lock is released, on
the thread that carried it out, with the same reason as the
zend_accel_schedule_restart_hook callback.
+ . ZEND_IN_RANGE_OF(x, T) was added to check whether the value of an integer
+ x is representable in the integer type T.
+ . ZEND_TYPE_MIN(T) and ZEND_TYPE_MAX(T) were added.
+
+- Deprecated:
+ . ZEND_LONG_INT_OVFL(), ZEND_LONG_INT_UDFL(), ZEND_LONG_EXCEEDS_INT(),
+ ZEND_LONG_UINT_OVFL(), ZEND_SIZE_T_INT_OVFL(), ZEND_SIZE_T_UINT_OVFL() and
+ the *_CAN_OVFL_* flags were deprecated. Use ZEND_IN_RANGE_OF() instead.
========================
2. Build system changes
diff --git a/Zend/zend_multiply.h b/Zend/zend_multiply.h
index 6457f85f64f..253e069eb74 100644
--- a/Zend/zend_multiply.h
+++ b/Zend/zend_multiply.h
@@ -119,7 +119,7 @@
#define ZEND_SIGNED_MULTIPLY_LONG(a, b, lval, dval, usedval) do { \
int64_t __result = (int64_t) (a) * (int64_t) (b); \
- if (__result > ZEND_LONG_MAX || __result < ZEND_LONG_MIN) { \
+ if (!ZEND_IN_RANGE_OF(__result, zend_long)) { \
(dval) = (double) __result; \
(usedval) = 1; \
} else { \
diff --git a/Zend/zend_portability.h b/Zend/zend_portability.h
index 193a28259f0..612de777869 100644
--- a/Zend/zend_portability.h
+++ b/Zend/zend_portability.h
@@ -89,8 +89,6 @@ using std::memory_order_acquire;
#include <intrin.h>
#endif
-#include "zend_range_check.h"
-
/* GCC x.y.z supplies __GNUC__ = x and __GNUC_MINOR__ = y */
#ifdef __GNUC__
# define ZEND_GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
@@ -956,4 +954,7 @@ static zend_always_inline uint64_t ZEND_BYTES_SWAP64(uint64_t u)
# define ZEND_OPCACHE_SHM_REATTACHMENT 1
#endif
+/* Last, as its declarations use ZEND_ATTRIBUTE_DEPRECATED. */
+#include "zend_range_check.h"
+
#endif /* ZEND_PORTABILITY_H */
diff --git a/Zend/zend_range_check.h b/Zend/zend_range_check.h
index ed61097419f..97a1bfa181e 100644
--- a/Zend/zend_range_check.h
+++ b/Zend/zend_range_check.h
@@ -12,6 +12,7 @@
| SPDX-License-Identifier: BSD-3-Clause |
+----------------------------------------------------------------------+
| Authors: Anatol Belski <ab@php.net> |
+ | Marc Bennewitz <marc@mabe.berlin> |
+----------------------------------------------------------------------+
*/
@@ -20,47 +21,137 @@
#include "zend_long.h"
-/* Flag macros for basic range recognition. Notable is that
- always sizeof(signed) == sizeof(unsigned), so no need to
- overcomplicate things. */
-#if SIZEOF_INT < SIZEOF_ZEND_LONG
-# define ZEND_LONG_CAN_OVFL_INT 1
-# define ZEND_LONG_CAN_OVFL_UINT 1
-#endif
+/* _ZEND_INT_TYPE_CHECK(T): the integer constant 0,
+ * or a compile error unless T is an integer type not wider than intmax_t. */
+#ifndef __cplusplus
+/* C: a static_assert() cannot appear in an expression itself,
+ * but it can as a member of a struct of which only the size is taken.
+ * The "% 1" only compiles for an integer operand. */
+# include <assert.h>
-#if SIZEOF_INT < SIZEOF_SIZE_T
-/* size_t can always overflow signed int on the same platform.
- Furthermore, by the current design, size_t can always
- overflow zend_long. */
-# define ZEND_SIZE_T_CAN_OVFL_UINT 1
+# define _ZEND_INT_TYPE_CHECK(T) \
+ ((int)(0 * sizeof(struct { \
+ static_assert( \
+ sizeof((T)0 % 1) && sizeof(T) <= sizeof(intmax_t), \
+ "T must be an integer type not wider than intmax_t" \
+ ); \
+ char zend_dummy; \
+ })))
+#else
+/* C++ does not allow to define a struct within sizeof(),
+ * so the static_assert() lives in a class template instead,
+ * which taking the size of instantiates. */
+extern "C++" {
+# include <cstdint>
+# include <type_traits>
+ template<typename T> struct _zend_int_type_check {
+ static_assert(std::is_integral<T>::value && sizeof(T) <= sizeof(intmax_t),
+ "T must be an integer type not wider than intmax_t");
+ };
+}
+
+# define _ZEND_INT_TYPE_CHECK(T) ((int)(0 * sizeof(_zend_int_type_check<T>)))
#endif
+/* _ZEND_TYPE_IS_SIGNED(T): whether the integer type T is signed, as an integer constant expression. */
+#define _ZEND_TYPE_IS_SIGNED(T) (!((T)-1 > (T)0))
-/* zend_long vs. (unsigned) int checks. */
-#ifdef ZEND_LONG_CAN_OVFL_INT
-# define ZEND_LONG_INT_OVFL(zlong) UNEXPECTED((zlong) > (zend_long)INT_MAX)
-# define ZEND_LONG_INT_UDFL(zlong) UNEXPECTED((zlong) < (zend_long)INT_MIN)
-# define ZEND_LONG_EXCEEDS_INT(zlong) UNEXPECTED(ZEND_LONG_INT_OVFL(zlong) || ZEND_LONG_INT_UDFL(zlong))
-# define ZEND_LONG_UINT_OVFL(zlong) UNEXPECTED((zlong) < 0 || (zlong) > (zend_long)UINT_MAX)
-#else
-# define ZEND_LONG_INT_OVFL(zl) (0)
-# define ZEND_LONG_INT_UDFL(zl) (0)
-# define ZEND_LONG_EXCEEDS_INT(zlong) (0)
-# define ZEND_LONG_UINT_OVFL(zl) UNEXPECTED((zl) < 0)
-#endif
+/* ZEND_TYPE_MAX(T): the largest value of the integer type T, as an integer constant expression,
+ * for types without a constant of their own such as time_t.
+ * T may be any signed or unsigned integer type not wider than intmax_t. */
+#define ZEND_TYPE_MAX(T) (_ZEND_INT_TYPE_CHECK(T) + (_ZEND_TYPE_IS_SIGNED(T) \
+ ? (((((T)1 << (sizeof(T) * CHAR_BIT - 2)) - 1) * 2) + 1) \
+ : (T)-1 \
+))
+
+/* ZEND_TYPE_MIN(T): the smallest value of the integer type T, as an integer constant expression.
+ * T may be any signed or unsigned integer type not wider than intmax_t. */
+#define ZEND_TYPE_MIN(T) (_ZEND_TYPE_IS_SIGNED(T) ? -ZEND_TYPE_MAX(T) - 1 : (T)0)
+
+/* ZEND_IN_RANGE_OF */
+
+static inline bool _zend_in_range_signed(intmax_t v, intmax_t min, uintmax_t max)
+{
+ if (max <= INTMAX_MAX) {
+ return v >= min && v <= (intmax_t)max;
+ }
+ return v >= 0; /* T is a uintmax_t-wide unsigned type */
+}
+
+static inline bool _zend_in_range_unsigned(uintmax_t v, uintmax_t max)
+{
+ return v <= max;
+}
+
+#define _ZEND_IN_RANGE_SIGNED(x, T) _zend_in_range_signed((intmax_t)(x), ZEND_TYPE_MIN(T), ZEND_TYPE_MAX(T))
+#define _ZEND_IN_RANGE_UNSIGNED(x, T) _zend_in_range_unsigned((uintmax_t)(x), ZEND_TYPE_MAX(T))
+
+#ifndef __cplusplus
+/* C: _Generic dispatches on the promoted type of x, without evaluating it. */
-/* size_t vs (unsigned) int checks. */
-#define ZEND_SIZE_T_INT_OVFL(size) UNEXPECTED((size) > (size_t)INT_MAX)
-#ifdef ZEND_SIZE_T_CAN_OVFL_UINT
-# define ZEND_SIZE_T_UINT_OVFL(size) UNEXPECTED((size) > (size_t)UINT_MAX)
+/* ZEND_IN_RANGE_OF(x, T): whether the value of the integer expression x is representable in the integer type T.
+ * x and T may be any signed or unsigned integer types not wider than intmax_t.
+ * x is evaluated exactly once. */
+# define ZEND_IN_RANGE_OF(x, T) EXPECTED(_Generic((x) + 0, \
+ int: _ZEND_IN_RANGE_SIGNED(x, T), \
+ long: _ZEND_IN_RANGE_SIGNED(x, T), \
+ long long: _ZEND_IN_RANGE_SIGNED(x, T), \
+ unsigned int: _ZEND_IN_RANGE_UNSIGNED(x, T), \
+ unsigned long: _ZEND_IN_RANGE_UNSIGNED(x, T), \
+ unsigned long long: _ZEND_IN_RANGE_UNSIGNED(x, T) \
+))
#else
-# define ZEND_SIZE_T_UINT_OVFL(size) (0)
+/* C++ has no _Generic (g++ and MSVC reject it).
+ * A function template deduces the type of x instead.
+ * The unary + applies the integer promotions, as (x) + 0 does for C. */
+extern "C++" {
+ template<typename T, typename X>
+ inline bool _zend_in_range_of(X x) {
+ static_assert(std::is_integral<X>::value && sizeof(X) <= sizeof(intmax_t), "x must be an integer not wider than intmax_t");
+
+ return std::is_signed<X>::value
+ ? _ZEND_IN_RANGE_SIGNED(x, T)
+ : _ZEND_IN_RANGE_UNSIGNED(x, T);
+ }
+}
+
+/* ZEND_IN_RANGE_OF(x, T): whether the value of the integer expression x is representable in the integer type T.
+ * x and T may be any signed or unsigned integer types not wider than intmax_t.
+ * x is evaluated exactly once. */
+# define ZEND_IN_RANGE_OF(x, T) EXPECTED(_zend_in_range_of<T>(+(x)))
#endif
/* Comparison zend_long vs size_t */
-#define ZEND_SIZE_T_GT_ZEND_LONG(size, zlong) ((zlong) < 0 || (size) > (size_t)(zlong))
+#define ZEND_SIZE_T_GT_ZEND_LONG(size, zlong) ((zlong) < 0 || (size) > (size_t)(zlong))
#define ZEND_SIZE_T_GTE_ZEND_LONG(size, zlong) ((zlong) < 0 || (size) >= (size_t)(zlong))
-#define ZEND_SIZE_T_LT_ZEND_LONG(size, zlong) ((zlong) >= 0 && (size) < (size_t)(zlong))
+#define ZEND_SIZE_T_LT_ZEND_LONG(size, zlong) ((zlong) >= 0 && (size) < (size_t)(zlong))
#define ZEND_SIZE_T_LTE_ZEND_LONG(size, zlong) ((zlong) >= 0 && (size) <= (size_t)(zlong))
+/* -- DEPRECATED -- */
+
+/* The zend_long and size_t vs. (unsigned) int checks below are deprecated, use ZEND_IN_RANGE_OF() instead. */
+ZEND_ATTRIBUTE_DEPRECATED static inline void _zend_deprecated_use_ZEND_IN_RANGE_OF_instead(void) {}
+
+#if SIZEOF_INT < SIZEOF_ZEND_LONG
+# define ZEND_LONG_CAN_OVFL_INT 1 /* Deprecated */
+# define ZEND_LONG_CAN_OVFL_UINT 1 /* Deprecated */
+# define ZEND_LONG_INT_OVFL(zlong) (_zend_deprecated_use_ZEND_IN_RANGE_OF_instead(), UNEXPECTED((zlong) > (zend_long)INT_MAX))
+# define ZEND_LONG_INT_UDFL(zlong) (_zend_deprecated_use_ZEND_IN_RANGE_OF_instead(), UNEXPECTED((zlong) < (zend_long)INT_MIN))
+# define ZEND_LONG_EXCEEDS_INT(zlong) (_zend_deprecated_use_ZEND_IN_RANGE_OF_instead(), UNEXPECTED((zlong) > (zend_long)INT_MAX || (zlong) < (zend_long)INT_MIN))
+# define ZEND_LONG_UINT_OVFL(zlong) (_zend_deprecated_use_ZEND_IN_RANGE_OF_instead(), UNEXPECTED((zlong) < 0 || (zlong) > (zend_long)UINT_MAX))
+#else
+# define ZEND_LONG_INT_OVFL(zl) (_zend_deprecated_use_ZEND_IN_RANGE_OF_instead(), 0)
+# define ZEND_LONG_INT_UDFL(zl) (_zend_deprecated_use_ZEND_IN_RANGE_OF_instead(), 0)
+# define ZEND_LONG_EXCEEDS_INT(zlong) (_zend_deprecated_use_ZEND_IN_RANGE_OF_instead(), 0)
+# define ZEND_LONG_UINT_OVFL(zl) (_zend_deprecated_use_ZEND_IN_RANGE_OF_instead(), UNEXPECTED((zl) < 0))
+#endif
+
+#define ZEND_SIZE_T_INT_OVFL(size) (_zend_deprecated_use_ZEND_IN_RANGE_OF_instead(), UNEXPECTED((size) > (size_t)INT_MAX))
+#if SIZEOF_INT < SIZEOF_SIZE_T
+# define ZEND_SIZE_T_CAN_OVFL_UINT 1 /* Deprecated */
+# define ZEND_SIZE_T_UINT_OVFL(size) (_zend_deprecated_use_ZEND_IN_RANGE_OF_instead(), UNEXPECTED((size) > (size_t)UINT_MAX))
+#else
+# define ZEND_SIZE_T_UINT_OVFL(size) (_zend_deprecated_use_ZEND_IN_RANGE_OF_instead(), 0)
+#endif
+
#endif /* ZEND_RANGE_CHECK_H */
diff --git a/ext/bcmath/bcmath.c b/ext/bcmath/bcmath.c
index 3b718df1ffb..1c8f21ed8c4 100644
--- a/ext/bcmath/bcmath.c
+++ b/ext/bcmath/bcmath.c
@@ -157,7 +157,7 @@ static zend_always_inline zend_result bcmath_check_scale(zend_long scale, uint32
static zend_result bcmath_check_precision(zend_long precision, uint32_t arg_num)
{
- if (ZEND_LONG_INT_OVFL(precision)) {
+ if (precision > 0 && !ZEND_IN_RANGE_OF(precision, int)) {
zend_argument_value_error(arg_num, "must be between " ZEND_LONG_FMT " and %d",
(zend_long) ZEND_LONG_MIN, INT_MAX);
return FAILURE;
diff --git a/ext/calendar/calendar.c b/ext/calendar/calendar.c
index 14daf3a5e67..d822eab49dc 100644
--- a/ext/calendar/calendar.c
+++ b/ext/calendar/calendar.c
@@ -255,7 +255,7 @@ PHP_FUNCTION(cal_to_jd)
RETURN_THROWS();
}
- if (UNEXPECTED(ZEND_LONG_EXCEEDS_INT(day))) {
+ if (!ZEND_IN_RANGE_OF(day, int32_t)) {
zend_argument_value_error(3, "must be between %d and %d", INT32_MIN, INT32_MAX);
RETURN_THROWS();
}
@@ -516,7 +516,7 @@ PHP_FUNCTION(jewishtojd)
RETURN_THROWS();
}
- if (ZEND_LONG_EXCEEDS_INT(year)) {
+ if (!ZEND_IN_RANGE_OF(year, int)) {
zend_argument_value_error(3, "must be between %d and %d", INT_MIN, INT_MAX);
RETURN_THROWS();
}
diff --git a/ext/calendar/julian.c b/ext/calendar/julian.c
index d539e2b45bd..6d75e93480d 100644
--- a/ext/calendar/julian.c
+++ b/ext/calendar/julian.c
@@ -176,7 +176,7 @@ void SdnToJulian(
/* Calculate the year and day of year (1 <= dayOfYear <= 366). */
{
long yearl = temp / DAYS_PER_4_YEARS;
- if (yearl > INT_MAX || yearl < INT_MIN) {
+ if (!ZEND_IN_RANGE_OF(yearl, int)) {
goto fail;
}
year = (int) yearl;
diff --git a/ext/curl/interface.c b/ext/curl/interface.c
index 9c5dd357d2c..02b8f07ad30 100644
--- a/ext/curl/interface.c
+++ b/ext/curl/interface.c
@@ -3071,7 +3071,7 @@ PHP_FUNCTION(curl_escape)
ch = Z_CURL_P(zid);
- if (ZEND_SIZE_T_INT_OVFL(ZSTR_LEN(str))) {
+ if (!ZEND_IN_RANGE_OF(ZSTR_LEN(str), int)) {
RETURN_FALSE;
}
@@ -3100,7 +3100,7 @@ PHP_FUNCTION(curl_unescape)
ch = Z_CURL_P(zid);
- if (ZEND_SIZE_T_INT_OVFL(ZSTR_LEN(str))) {
+ if (!ZEND_IN_RANGE_OF(ZSTR_LEN(str), int)) {
RETURN_FALSE;
}
diff --git a/ext/dba/dba.c b/ext/dba/dba.c
index b7f6d0d49c0..dc999c17dfa 100644
--- a/ext/dba/dba.c
+++ b/ext/dba/dba.c
@@ -1094,7 +1094,7 @@ PHP_FUNCTION(dba_fetch)
ZEND_PARSE_PARAMETERS_END();
}
- if (ZEND_LONG_EXCEEDS_INT(skip)) {
+ if (!ZEND_IN_RANGE_OF(skip, int)) {
zend_argument_value_error(3, "must be between %d and %d", INT_MIN, INT_MAX);
RETURN_THROWS();
}
diff --git a/ext/dom/characterdata.c b/ext/dom/characterdata.c
index 80dce80cf2f..9677a71bac1 100644
--- a/ext/dom/characterdata.c
+++ b/ext/dom/characterdata.c
@@ -119,7 +119,7 @@ PHP_METHOD(DOMCharacterData, substringData)
const xmlChar *cur = php_dom_get_content_or_empty(node);
length = xmlUTF8Strlen(cur);
- if (ZEND_LONG_INT_OVFL(offset_input) || ZEND_LONG_INT_OVFL(count_input)) {
+ if ((offset_input > 0 && !ZEND_IN_RANGE_OF(offset_input, int)) || (count_input > 0 && !ZEND_IN_RANGE_OF(count_input, int))) {
php_dom_throw_error(INDEX_SIZE_ERR, dom_get_strict_error(intern->document));
RETURN_FALSE;
}
@@ -206,7 +206,7 @@ static void dom_character_data_insert_data(INTERNAL_FUNCTION_PARAMETERS, bool re
length = xmlUTF8Strlen(cur);
- if (ZEND_LONG_INT_OVFL(offset_input)) {
+ if (offset_input > 0 && !ZEND_IN_RANGE_OF(offset_input, int)) {
php_dom_throw_error(INDEX_SIZE_ERR, dom_get_strict_error(intern->document));
RETURN_FALSE;
}
@@ -271,7 +271,7 @@ static void dom_character_data_delete_data(INTERNAL_FUNCTION_PARAMETERS, bool re
length = xmlUTF8Strlen(cur);
- if (offset < 0 || ZEND_LONG_INT_OVFL(offset) || ZEND_LONG_INT_OVFL(count_input) || offset > length) {
+ if (offset < 0 || !ZEND_IN_RANGE_OF(offset, int) || (count_input > 0 && !ZEND_IN_RANGE_OF(count_input, int)) || offset > length) {
php_dom_throw_error(INDEX_SIZE_ERR, dom_get_strict_error(intern->document));
RETURN_FALSE;
}
@@ -341,7 +341,7 @@ static void dom_character_data_replace_data(INTERNAL_FUNCTION_PARAMETERS, bool r
length = xmlUTF8Strlen(cur);
- if (offset < 0 || ZEND_LONG_INT_OVFL(offset) || ZEND_LONG_INT_OVFL(count_input) || offset > length) {
+ if (offset < 0 || !ZEND_IN_RANGE_OF(offset, int) || (count_input > 0 && !ZEND_IN_RANGE_OF(count_input, int)) || offset > length) {
php_dom_throw_error(INDEX_SIZE_ERR, dom_get_strict_error(intern->document));
RETURN_FALSE;
}
diff --git a/ext/dom/document.c b/ext/dom/document.c
index 427a8f5dc08..091fa12b301 100644
--- a/ext/dom/document.c
+++ b/ext/dom/document.c
@@ -1532,11 +1532,11 @@ static void dom_parse_document(INTERNAL_FUNCTION_PARAMETERS, int mode)
zend_argument_must_not_be_empty_error(1);
RETURN_THROWS();
}
- if (ZEND_SIZE_T_INT_OVFL(source_len)) {
+ if (!ZEND_IN_RANGE_OF(source_len, int)) {
php_error_docref(NULL, E_WARNING, "Input string is too long");
RETURN_FALSE;
}
- if (ZEND_LONG_EXCEEDS_INT(options)) {
+ if (!ZEND_IN_RANGE_OF(options, int)) {
php_error_docref(NULL, E_WARNING, "Invalid options");
RETURN_FALSE;
}
@@ -1794,7 +1794,7 @@ PHP_METHOD(DOMDocument, xinclude)
RETURN_THROWS();
}
- if (ZEND_LONG_EXCEEDS_INT(flags)) {
+ if (!ZEND_IN_RANGE_OF(flags, int)) {
php_error_docref(NULL, E_WARNING, "Invalid flags");
RETURN_FALSE;
}
@@ -1820,7 +1820,7 @@ PHP_METHOD(Dom_XMLDocument, xinclude)
RETURN_THROWS();
}
- if (ZEND_LONG_EXCEEDS_INT(flags)) {
+ if (!ZEND_IN_RANGE_OF(flags, int)) {
zend_argument_value_error(1, "is too large");
RETURN_THROWS();
}
@@ -2105,7 +2105,7 @@ static void dom_load_html(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ */
RETURN_THROWS();
}
- if (ZEND_LONG_EXCEEDS_INT(options)) {
+ if (!ZEND_IN_RANGE_OF(options, int)) {
php_error_docref(NULL, E_WARNING, "Invalid options");
RETURN_FALSE;
}
@@ -2117,7 +2117,7 @@ static void dom_load_html(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ */
}
ctxt = htmlCreateFileParserCtxt(source, NULL);
} else {
- if (ZEND_SIZE_T_INT_OVFL(source_len)) {
+ if (!ZEND_IN_RANGE_OF(source_len, int)) {
php_error_docref(NULL, E_WARNING, "Input string is too long");
RETURN_FALSE;
}
diff --git a/ext/dom/dom_iterators.c b/ext/dom/dom_iterators.c
index 7566dd8b61a..00dcc2464c5 100644
--- a/ext/dom/dom_iterators.c
+++ b/ext/dom/dom_iterators.c
@@ -86,7 +86,7 @@ xmlNodePtr php_dom_libxml_hash_iter(xmlHashTable *ht, zend_long index)
if (index < 0) {
return NULL;
}
- if (UNEXPECTED(ZEND_LONG_INT_OVFL(index))) {
+ if (!ZEND_IN_RANGE_OF(index, int)) {
zend_value_error("must be between 0 and %d", INT_MAX);
return NULL;
}
diff --git a/ext/dom/element.c b/ext/dom/element.c
index bab828815a6..af6a5897b4d 100644
--- a/ext/dom/element.c
+++ b/ext/dom/element.c
@@ -1741,7 +1741,7 @@ static void dom_element_insert_adjacent_text(INTERNAL_FUNCTION_PARAMETERS, zend_
DOM_GET_THIS_OBJ(thisp, id, xmlNodePtr, this_intern);
- if (UNEXPECTED(ZEND_SIZE_T_INT_OVFL(ZSTR_LEN(data)))) {
+ if (!ZEND_IN_RANGE_OF(ZSTR_LEN(data), int)) {
zend_argument_value_error(2, "is too long");
RETURN_THROWS();
}
diff --git a/ext/dom/namednodemap.c b/ext/dom/namednodemap.c
index d665bbbaebd..88e5220a7fb 100644
--- a/ext/dom/namednodemap.c
+++ b/ext/dom/namednodemap.c
@@ -74,7 +74,7 @@ PHP_METHOD(DOMNamedNodeMap, item)
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_LONG(index)
ZEND_PARSE_PARAMETERS_END();
- if (index < 0 || ZEND_LONG_INT_OVFL(index)) {
+ if (index < 0 || !ZEND_IN_RANGE_OF(index, int)) {
zend_argument_value_error(1, "must be between 0 and %d", INT_MAX);
RETURN_THROWS();
}
diff --git a/ext/dom/php_dom.c b/ext/dom/php_dom.c
index 0833d9a3c9b..2f9cebe700a 100644
--- a/ext/dom/php_dom.c
+++ b/ext/dom/php_dom.c
@@ -2424,7 +2424,7 @@ static zval *dom_nodemap_read_dimension(zend_object *object, zval *offset, int t
}
/* see PHP_METHOD(DOMNamedNodeMap, item) */
- if (UNEXPECTED(lval < 0 || ZEND_LONG_INT_OVFL(lval))) {
+ if (UNEXPECTED(lval < 0 || !ZEND_IN_RANGE_OF(lval, int))) {
zend_value_error("must be between 0 and %d", INT_MAX);
return NULL;
}
diff --git a/ext/dom/text.c b/ext/dom/text.c
index 357ff196949..71478308561 100644
--- a/ext/dom/text.c
+++ b/ext/dom/text.c
@@ -115,7 +115,7 @@ PHP_METHOD(DOMText, splitText)
const xmlChar *cur = php_dom_get_content_or_empty(node);
length = xmlUTF8Strlen(cur);
- if (ZEND_LONG_INT_OVFL(offset) || (int)offset > length) {
+ if (!ZEND_IN_RANGE_OF(offset, int) || (int)offset > length) {
if (php_dom_follow_spec_intern(intern)) {
php_dom_throw_error(INDEX_SIZE_ERR, /* strict */ true);
}
diff --git a/ext/dom/xml_document.c b/ext/dom/xml_document.c
index 707356227af..f82e689720c 100644
--- a/ext/dom/xml_document.c
+++ b/ext/dom/xml_document.c
@@ -149,7 +149,7 @@ static void load_from_helper(INTERNAL_FUNCTION_PARAMETERS, int mode)
RETURN_THROWS();
}
- if (ZEND_SIZE_T_INT_OVFL(source_len)) {
+ if (!ZEND_IN_RANGE_OF(source_len, int)) {
zend_argument_value_error(1, "is too long");
RETURN_THROWS();
}
diff --git a/ext/gd/gd.c b/ext/gd/gd.c
index 6b9fd5c913c..5f472f68c35 100644
--- a/ext/gd/gd.c
+++ b/ext/gd/gd.c
@@ -665,7 +665,7 @@ PHP_FUNCTION(imagesetstyle)
zend_argument_type_error(2, "must only have elements of type int, %s given", zend_zval_type_name(item));
RETURN_THROWS();
}
- if (ZEND_LONG_EXCEEDS_INT(tmp)) {
+ if (!ZEND_IN_RANGE_OF(tmp, int)) {
efree(stylearr);
zend_argument_value_error(2, "elements must be between %d and %d", INT_MIN, INT_MAX);
RETURN_THROWS();
@@ -744,7 +744,7 @@ PHP_FUNCTION(imagetruecolortopalette)
im = php_gd_libgdimageptr_from_zval_p(IM);
- if (ncolors <= 0 || ZEND_LONG_INT_OVFL(ncolors)) {
+ if (ncolors <= 0 || !ZEND_IN_RANGE_OF(ncolors, int)) {
zend_argument_value_error(3, "must be between 1 and %d", INT_MAX);
RETURN_THROWS();
}
@@ -849,7 +849,7 @@ PHP_FUNCTION(imagefilledellipse)
Z_PARAM_LONG(color)
ZEND_PARSE_PARAMETERS_END();
- if (w < 0 || ZEND_LONG_INT_OVFL(w)) {
+ if (w < 0 || !ZEND_IN_RANGE_OF(w, int)) {
zend_argument_value_error(4, "must be between 0 and %d", INT_MAX);
RETURN_THROWS();
}
@@ -1818,7 +1818,7 @@ static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type)
}
/* quality must fit in an int */
- if (quality < INT_MIN || quality > INT_MAX) {
+ if (!ZEND_IN_RANGE_OF(quality, int)) {
php_error_docref(NULL, E_WARNING, "Argument #3 ($chunk_size) must be between %d and %d", INT_MIN, INT_MAX);
RETURN_FALSE;
}
@@ -3679,12 +3679,12 @@ static void php_image_filter_scatter(INTERNAL_FUNCTION_PARAMETERS)
Z_PARAM_ARRAY(hash_colors)
ZEND_PARSE_PARAMETERS_END();
- if (scatter_sub < 0 || ZEND_SIZE_T_INT_OVFL(scatter_sub)) {
+ if (scatter_sub < 0 || !ZEND_IN_RANGE_OF(scatter_sub, int)) {
zend_argument_value_error(3, "must be between 0 and %d", INT_MAX);
RETURN_THROWS();
}
- if (scatter_plus < 0 || ZEND_SIZE_T_INT_OVFL(scatter_plus)) {
+ if (scatter_plus < 0 || !ZEND_IN_RANGE_OF(scatter_plus, int)) {
zend_argument_value_error(4, "must be between 0 and %d", INT_MAX);
RETURN_THROWS();
}
@@ -3712,7 +3712,7 @@ static void php_image_filter_scatter(INTERNAL_FUNCTION_PARAMETERS)
zend_argument_type_error(5, "must be of type int, %s given", zend_zval_type_name(color));
RETURN_THROWS();
}
- if (tmp < 0 || ZEND_LONG_INT_OVFL(tmp)) {
+ if (tmp < 0 || !ZEND_IN_RANGE_OF(tmp, int)) {
efree(colors);
zend_argument_value_error(5, "value must be between 0 and %d", INT_MAX);
RETURN_THROWS();
@@ -3894,7 +3894,7 @@ static bool php_gd_zval_try_get_c_int(zval *tmp, const char *field, int *res) {
zend_argument_type_error(2, "\"%s\" key must be of type int, %s given", field, zend_zval_type_name(tmp));
return false;
}
- if (UNEXPECTED(ZEND_LONG_EXCEEDS_INT(r))) {
+ if (!ZEND_IN_RANGE_OF(r, int)) {
zend_argument_value_error(2, "\"%s\" key must be between %d and %d", field, INT_MIN, INT_MAX);
return false;
}
@@ -4090,12 +4090,12 @@ PHP_FUNCTION(imagescale)
}
}
- if (tmp_w <= 0 || ZEND_SIZE_T_INT_OVFL(tmp_w)) {
+ if (tmp_w <= 0 || !ZEND_IN_RANGE_OF(tmp_w, int)) {
zend_argument_value_error(2, "must be between 1 and %d", INT_MAX);
RETURN_THROWS();
}
- if (tmp_h <= 0 || ZEND_SIZE_T_INT_OVFL(tmp_h)) {
+ if (tmp_h <= 0 || !ZEND_IN_RANGE_OF(tmp_h, int)) {
zend_argument_value_error(3, "must be between 1 and %d", INT_MAX);
RETURN_THROWS();
}
@@ -4432,25 +4432,25 @@ PHP_FUNCTION(imageresolution)
im = php_gd_libgdimageptr_from_zval_p(IM);
if (!res_x_is_null && !res_y_is_null) {
- if (res_x < 0 || ZEND_SIZE_T_UINT_OVFL(res_x)) {
+ if (!ZEND_IN_RANGE_OF(res_x, unsigned int)) {
zend_argument_value_error(2, "must be between 0 and %u", UINT_MAX);
RETURN_THROWS();
}
- if (res_y < 0 || ZEND_SIZE_T_UINT_OVFL(res_y)) {
+ if (!ZEND_IN_RANGE_OF(res_y, unsigned int)) {
zend_argument_value_error(3, "must be between 0 and %u", UINT_MAX);
RETURN_THROWS();
}
gdImageSetResolution(im, res_x, res_y);
RETURN_TRUE;
} else if (!res_x_is_null && res_y_is_null) {
- if (res_x < 0 || ZEND_SIZE_T_UINT_OVFL(res_x)) {
+ if (!ZEND_IN_RANGE_OF(res_x, unsigned int)) {
zend_argument_value_error(2, "must be between 0 and %u", UINT_MAX);
RETURN_THROWS();
}
gdImageSetResolution(im, res_x, res_x);
RETURN_TRUE;
} else if (res_x_is_null && !res_y_is_null) {
- if (res_y < 0 || ZEND_SIZE_T_UINT_OVFL(res_y)) {
+ if (!ZEND_IN_RANGE_OF(res_y, unsigned int)) {
zend_argument_value_error(3, "must be between 0 and %u", UINT_MAX);
RETURN_THROWS();
}
diff --git a/ext/gmp/gmp.c b/ext/gmp/gmp.c
index 0ee8ff69982..975fc2e7a8b 100644
--- a/ext/gmp/gmp.c
+++ b/ext/gmp/gmp.c
@@ -371,7 +371,7 @@ static zend_result shift_operator_helper(gmp_binary_ui_op_t op, zval *return_val
}
if (!have_shift_ui) {
- if (shift < 0 || shift > ULONG_MAX) {
+ if (!ZEND_IN_RANGE_OF(shift, unsigned long)) {
gmp_shift_operator_range_error(opcode);
return FAILURE;
}
@@ -1165,7 +1165,7 @@ ZEND_FUNCTION(gmp_binomial)
Z_PARAM_LONG(k)
ZEND_PARSE_PARAMETERS_END();
- if (k < 0 || k > ULONG_MAX) {
+ if (!ZEND_IN_RANGE_OF(k, unsigned long)) {
zend_argument_value_error(2, "must be between 0 and %lu", ULONG_MAX);
RETURN_THROWS();
}
@@ -1187,7 +1187,7 @@ ZEND_FUNCTION(gmp_pow)
Z_PARAM_LONG(exp)
ZEND_PARSE_PARAMETERS_END();
- if (exp < 0 || exp > ULONG_MAX) {
+ if (!ZEND_IN_RANGE_OF(exp, unsigned long)) {
zend_argument_value_error(2, "must be between 0 and %lu", ULONG_MAX);
RETURN_THROWS();
}
diff --git a/ext/hash/hash.c b/ext/hash/hash.c
index 20e8d120b5b..419206212eb 100644
--- a/ext/hash/hash.c
+++ b/ext/hash/hash.c
@@ -1290,7 +1290,7 @@ PHP_FUNCTION(mhash_keygen_s2k)
RETURN_THROWS();
}
- if (ZEND_LONG_INT_OVFL(l_bytes)) {
+ if (!ZEND_IN_RANGE_OF(l_bytes, int)) {
zend_argument_value_error(4, "must be less than or equal to %d", INT_MAX);
RETURN_THROWS();
}
diff --git a/ext/intl/breakiterator/breakiterator_methods.cpp b/ext/intl/breakiterator/breakiterator_methods.cpp
index 13f4fddf362..036b54deb26 100644
--- a/ext/intl/breakiterator/breakiterator_methods.cpp
+++ b/ext/intl/breakiterator/breakiterator_methods.cpp
@@ -188,7 +188,7 @@ static void _breakiter_int32_ret_int32(
BREAKITER_METHOD_FETCH_OBJECT;
- if (UNEXPECTED(arg < INT32_MIN || arg > INT32_MAX)) {
+ if (!ZEND_IN_RANGE_OF(arg, int32_t)) {
zend_argument_value_error(1, "must be between %d and %d", INT32_MIN, INT32_MAX);
RETURN_THROWS();
}
@@ -273,7 +273,7 @@ PHP_METHOD(IntlBreakIterator, isBoundary)
Z_PARAM_LONG(offset)
ZEND_PARSE_PARAMETERS_END();
- if (UNEXPECTED(offset < INT32_MIN || offset > INT32_MAX)) {
+ if (!ZEND_IN_RANGE_OF(offset, int32_t)) {
zend_argument_value_error(1, "must be between %d and %d", INT32_MIN, INT32_MAX);
RETURN_THROWS();
}
diff --git a/ext/intl/calendar/calendar_methods.cpp b/ext/intl/calendar/calendar_methods.cpp
index 990eea9eeaf..e74fc976fd7 100644
--- a/ext/intl/calendar/calendar_methods.cpp
+++ b/ext/intl/calendar/calendar_methods.cpp
@@ -50,7 +50,7 @@ using icu::Locale;
}
#define ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(argument, zpp_arg_position) \
- if (UNEXPECTED(argument < INT32_MIN || argument > INT32_MAX)) { \
+ if (!ZEND_IN_RANGE_OF(argument, int32_t)) { \
zend_argument_value_error(hasThis() ? ((zpp_arg_position)-1) : zpp_arg_position, \
"must be between %d and %d", INT32_MIN, INT32_MAX); \
RETURN_THROWS(); \
diff --git a/ext/intl/calendar/gregoriancalendar_methods.cpp b/ext/intl/calendar/gregoriancalendar_methods.cpp
index bb276ddedf0..a0a49cd06ea 100644
--- a/ext/intl/calendar/gregoriancalendar_methods.cpp
+++ b/ext/intl/calendar/gregoriancalendar_methods.cpp
@@ -41,7 +41,7 @@ using icu::UnicodeString;
using icu::StringPiece;
#define ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(argument, zpp_arg_position) \
- if (UNEXPECTED(argument < INT32_MIN || argument > INT32_MAX)) { \
+ if (!ZEND_IN_RANGE_OF(argument, int32_t)) { \
zend_argument_value_error(zpp_arg_position, "must be between %d and %d", INT32_MIN, INT32_MAX); \
RETURN_THROWS(); \
}
@@ -357,7 +357,7 @@ U_CFUNC PHP_FUNCTION(intlgregcal_is_leap_year)
}
- if (UNEXPECTED(year < INT32_MIN || year > INT32_MAX)) {
+ if (!ZEND_IN_RANGE_OF(year, int32_t)) {
zend_argument_value_error(hasThis() ? 1 : 2, "must be between %d and %d", INT32_MIN, INT32_MAX);
RETURN_THROWS();
}
diff --git a/ext/intl/dateformat/dateformat_parse.cpp b/ext/intl/dateformat/dateformat_parse.cpp
index cf7acd9f05a..28b76ea5cbf 100644
--- a/ext/intl/dateformat/dateformat_parse.cpp
+++ b/ext/intl/dateformat/dateformat_parse.cpp
@@ -172,7 +172,7 @@ U_CFUNC PHP_FUNCTION(datefmt_parse)
zend_argument_type_error(hasThis() ? 2 : 3, "must be of type int, %s given", zend_zval_value_name(z_parse_pos));
RETURN_THROWS();
}
- if (ZEND_LONG_EXCEEDS_INT(long_parse_pos)) {
+ if (!ZEND_IN_RANGE_OF(long_parse_pos, int32_t)) {
intl_error_set_code(NULL, U_ILLEGAL_ARGUMENT_ERROR);
intl_error_set_custom_msg(NULL, "String index is out of valid range.");
RETURN_FALSE;
@@ -215,7 +215,7 @@ U_CFUNC PHP_METHOD(IntlDateFormatter, parseToCalendar)
zend_argument_type_error(2, "must be of type int, %s given", zend_zval_value_name(z_parse_pos));
RETURN_THROWS();
}
- if (ZEND_LONG_EXCEEDS_INT(long_parse_pos)) {
+ if (!ZEND_IN_RANGE_OF(long_parse_pos, int32_t)) {
intl_error_set_code(NULL, U_ILLEGAL_ARGUMENT_ERROR);
intl_error_set_custom_msg(NULL, "String index is out of valid range.");
RETURN_FALSE;
@@ -257,7 +257,7 @@ U_CFUNC PHP_FUNCTION(datefmt_localtime)
zend_argument_type_error(hasThis() ? 2 : 3, "must be of type int, %s given", zend_zval_value_name(z_parse_pos));
RETURN_THROWS();
}
- if (ZEND_LONG_EXCEEDS_INT(long_parse_pos)) {
+ if (!ZEND_IN_RANGE_OF(long_parse_pos, int32_t)) {
intl_error_set_code(NULL, U_ILLEGAL_ARGUMENT_ERROR);
intl_error_set_custom_msg(NULL, "String index is out of valid range.");
RETURN_FALSE;
diff --git a/ext/intl/formatter/formatter_parse.cpp b/ext/intl/formatter/formatter_parse.cpp
index 0acab835085..a507f484b72 100644
--- a/ext/intl/formatter/formatter_parse.cpp
+++ b/ext/intl/formatter/formatter_parse.cpp
@@ -51,7 +51,7 @@ U_CFUNC PHP_FUNCTION( numfmt_parse )
if (zposition) {
zend_long long_position = zval_get_long(zposition);
- if (UNEXPECTED(long_position < INT32_MIN || long_position > INT32_MAX)) {
+ if (!ZEND_IN_RANGE_OF(long_position, int32_t)) {
zend_argument_value_error(hasThis() ? 3 : 4, "must be between %d and %d", INT32_MIN, INT32_MAX);
RETURN_THROWS();
}
@@ -95,7 +95,7 @@ U_CFUNC PHP_FUNCTION( numfmt_parse )
case FORMAT_TYPE_INT64:
{
int64_t val64 = result.getInt64(INTL_DATA_ERROR_CODE(nfo));
- if(val64 > ZEND_LONG_MAX || val64 < ZEND_LONG_MIN) {
+ if(!ZEND_IN_RANGE_OF(val64, zend_long)) {
RETVAL_DOUBLE(val64);
} else {
RETVAL_LONG((zend_long)val64);
@@ -166,7 +166,7 @@ U_CFUNC PHP_FUNCTION( numfmt_parse_currency )
if (zposition) {
zend_long long_position = zval_get_long(zposition);
- if (UNEXPECTED(long_position < INT32_MIN || long_position > INT32_MAX)) {
+ if (!ZEND_IN_RANGE_OF(long_position, int32_t)) {
zend_argument_value_error(hasThis() ? 3 : 4, "must be between %d and %d", INT32_MIN, INT32_MAX);
RETURN_THROWS();
}
diff --git a/ext/intl/grapheme/grapheme_string.cpp b/ext/intl/grapheme/grapheme_string.cpp
index 4acf636d54b..9c7fa09cb73 100644
--- a/ext/intl/grapheme/grapheme_string.cpp
+++ b/ext/intl/grapheme/grapheme_string.cpp
@@ -358,7 +358,7 @@ U_CFUNC PHP_FUNCTION(grapheme_substr)
Z_PARAM_PATH(locale, locale_len)
ZEND_PARSE_PARAMETERS_END();
- if (UNEXPECTED(lstart < INT32_MIN || lstart > INT32_MAX)) {
+ if (!ZEND_IN_RANGE_OF(lstart, int32_t)) {
zend_argument_value_error(2, "is too large");
RETURN_THROWS();
}
@@ -369,7 +369,7 @@ U_CFUNC PHP_FUNCTION(grapheme_substr)
length = str_len;
}
- if (UNEXPECTED(length < INT32_MIN || length > INT32_MAX)) {
+ if (!ZEND_IN_RANGE_OF(length, int32_t)) {
zend_argument_value_error(3, "is too large");
RETURN_THROWS();
}
diff --git a/ext/intl/msgformat/msgformat_helpers.cpp b/ext/intl/msgformat/msgformat_helpers.cpp
index d079703c2ec..db62f5e5ba0 100644
--- a/ext/intl/msgformat/msgformat_helpers.cpp
+++ b/ext/intl/msgformat/msgformat_helpers.cpp
@@ -639,7 +639,7 @@ void umsg_parse_helper(UMessageFormat *fmt, int *count, zval **args, UChar *sour
case Formattable::kInt64:
aInt64 = fargs[i].getInt64();
- if(aInt64 > ZEND_LONG_MAX || aInt64 < ZEND_LONG_MIN) {
+ if(!ZEND_IN_RANGE_OF(aInt64, zend_long)) {
ZVAL_DOUBLE(&(*args)[i], (double)aInt64);
} else {
ZVAL_LONG(&(*args)[i], (zend_long)aInt64);
diff --git a/ext/intl/resourcebundle/resourcebundle_class.cpp b/ext/intl/resourcebundle/resourcebundle_class.cpp
index a18a23c3a87..8b8afdbb9ce 100644
--- a/ext/intl/resourcebundle/resourcebundle_class.cpp
+++ b/ext/intl/resourcebundle/resourcebundle_class.cpp
@@ -190,7 +190,7 @@ static zval *resource_bundle_array_fetch(
key = ZSTR_VAL(offset_str);
rb->child = ures_getByKey(rb->me, key, rb->child, &INTL_DATA_ERROR_CODE(rb) );
} else {
- if (UNEXPECTED(offset_int < (zend_long)INT32_MIN || offset_int > (zend_long)INT32_MAX)) {
+ if (!ZEND_IN_RANGE_OF(offset_int, int32_t)) {
if (offset_arg_num) {
zend_argument_value_error(offset_arg_num, "index must be between %d and %d", INT32_MIN, INT32_MAX);
} else {
diff --git a/ext/intl/timezone/timezone_methods.cpp b/ext/intl/timezone/timezone_methods.cpp
index 89d725217b9..9cce645622f 100644
--- a/ext/intl/timezone/timezone_methods.cpp
+++ b/ext/intl/timezone/timezone_methods.cpp
@@ -133,7 +133,7 @@ PHP_INTL_FUNCTION_WITH_ERROR_RESET(intltz_create_enumeration)
} else if (timezone != nullptr) {
se = TimeZone::createEnumeration(ZSTR_VAL(timezone));
} else {
- if (UNEXPECTED(ZEND_LONG_EXCEEDS_INT(timezone_shift))) {
+ if (!ZEND_IN_RANGE_OF(timezone_shift, int32_t)) {
zend_argument_value_error(1, "must be between %d and %d", INT32_MIN, INT32_MAX);
RETURN_THROWS();
}
@@ -196,7 +196,7 @@ PHP_INTL_FUNCTION_WITH_ERROR_RESET(intltz_create_time_zone_id_enumeration)
}
if (!arg3isnull) {
- if (UNEXPECTED(ZEND_LONG_EXCEEDS_INT(offset_arg))) {
+ if (!ZEND_IN_RANGE_OF(offset_arg, int32_t)) {
zend_argument_value_error(3, "must be between %d and %d", INT32_MIN, INT32_MAX);
RETURN_THROWS();
}
@@ -294,7 +294,7 @@ PHP_INTL_FUNCTION_WITH_ERROR_RESET(intltz_get_equivalent_id)
Z_PARAM_LONG(index)
ZEND_PARSE_PARAMETERS_END();
- if (UNEXPECTED(ZEND_LONG_EXCEEDS_INT(index))) {
+ if (!ZEND_IN_RANGE_OF(index, int32_t)) {
zend_argument_value_error(2, "must be between %d and %d", INT32_MIN, INT32_MAX);
RETURN_THROWS();
}
diff --git a/ext/intl/uchar/uchar.cpp b/ext/intl/uchar/uchar.cpp
index 9479287b5e0..4b881a4b1c0 100644
--- a/ext/intl/uchar/uchar.cpp
+++ b/ext/intl/uchar/uchar.cpp
@@ -35,7 +35,7 @@ static inline int convert_cp(UChar32* pcp, const zend_string *string_codepoint,
int32_t i = 0;
const size_t string_codepoint_length = ZSTR_LEN(string_codepoint);
- if (UNEXPECTED(ZEND_SIZE_T_INT_OVFL(string_codepoint_length))) {
+ if (!ZEND_IN_RANGE_OF(string_codepoint_length, int32_t)) {
intl_error_set_code(NULL, U_ILLEGAL_ARGUMENT_ERROR);
intl_error_set_custom_msg(NULL, "Input string is too long.");
return FAILURE;
diff --git a/ext/json/json.c b/ext/json/json.c
index 9fe6211df92..a760724f466 100644
--- a/ext/json/json.c
+++ b/ext/json/json.c
@@ -249,7 +249,7 @@ PHP_FUNCTION(json_encode)
Z_PARAM_LONG(depth)
ZEND_PARSE_PARAMETERS_END();
- if (ZEND_LONG_EXCEEDS_INT(depth)) {
+ if (!ZEND_IN_RANGE_OF(depth, int)) {
zend_argument_value_error(3, "must be between %d and %d", INT_MIN, INT_MAX);
RETURN_THROWS();
}
diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c
index 539661d52c7..41921176f06 100644
--- a/ext/ldap/ldap.c
+++ b/ext/ldap/ldap.c
@@ -3215,7 +3215,7 @@ PHP_FUNCTION(ldap_set_option)
RETURN_THROWS();
}
- if (ZEND_LONG_EXCEEDS_INT(lval)) {
+ if (!ZEND_IN_RANGE_OF(lval, int)) {
zend_argument_value_error(3, "is too large");
RETURN_THROWS();
}
diff --git a/ext/mbstring/php_mbregex.c b/ext/mbstring/php_mbregex.c
index df1553b54b6..101c10ff9f3 100644
--- a/ext/mbstring/php_mbregex.c
+++ b/ext/mbstring/php_mbregex.c
@@ -881,11 +881,11 @@ static int _php_mb_onig_search(regex_t* reg, const OnigUChar* str, const OnigUCh
OnigMatchParam *mp = onig_new_match_param();
int err;
onig_initialize_match_param(mp);
- if (!ZEND_LONG_UINT_OVFL(MBSTRG(regex_stack_limit))) {
+ if (ZEND_IN_RANGE_OF(MBSTRG(regex_stack_limit), unsigned int)) {
onig_set_match_stack_limit_size_of_match_param(mp, (unsigned int)MBSTRG(regex_stack_limit));
}
- if (!ZEND_LONG_UINT_OVFL(MBSTRG(regex_retry_limit))) {
- onig_set_retry_limit_in_match_of_match_param(mp, (unsigned int)MBSTRG(regex_retry_limit));
+ if (ZEND_IN_RANGE_OF(MBSTRG(regex_retry_limit), unsigned long)) {
+ onig_set_retry_limit_in_match_of_match_param(mp, (unsigned long)MBSTRG(regex_retry_limit));
}
/* search */
err = onig_search_with_param(reg, str, end, start, range, region, option, mp);
@@ -1310,11 +1310,11 @@ PHP_FUNCTION(mb_ereg_match)
mp = onig_new_match_param();
onig_initialize_match_param(mp);
- if (MBSTRG(regex_stack_limit) > 0 && MBSTRG(regex_stack_limit) < UINT_MAX) {
+ if (MBSTRG(regex_stack_limit) > 0 && ZEND_IN_RANGE_OF(MBSTRG(regex_stack_limit), unsigned int)) {
onig_set_match_stack_limit_size_of_match_param(mp, (unsigned int)MBSTRG(regex_stack_limit));
}
- if (MBSTRG(regex_retry_limit) > 0 && MBSTRG(regex_retry_limit) < UINT_MAX) {
- onig_set_retry_limit_in_match_of_match_param(mp, (unsigned int)MBSTRG(regex_retry_limit));
+ if (MBSTRG(regex_retry_limit) > 0 && ZEND_IN_RANGE_OF(MBSTRG(regex_retry_limit), unsigned long)) {
+ onig_set_retry_limit_in_match_of_match_param(mp, (unsigned long)MBSTRG(regex_retry_limit));
}
/* match */
err = onig_match_with_param(re, (OnigUChar *)string, (OnigUChar *)(string + string_len), (OnigUChar *)string, NULL, 0, mp);
diff --git a/ext/mbstring/tests/retry_limit_above_uint_max.phpt b/ext/mbstring/tests/retry_limit_above_uint_max.phpt
new file mode 100644
index 00000000000..371699d78a3
--- /dev/null
+++ b/ext/mbstring/tests/retry_limit_above_uint_max.phpt
@@ -0,0 +1,32 @@
+--TEST--
+Oniguruma retry limit beyond the range of an unsigned int
+--EXTENSIONS--
+mbstring
+--SKIPIF--
+<?php
+if (!function_exists('mb_ereg')) die('skip mb_ereg not available');
+if (@version_compare(MB_ONIGURUMA_VERSION, '6.9.3') < 0) {
+ die('skip requires Oniguruma >= 6.9.3');
+}
+if (PHP_INT_SIZE <= 4) die('skip a limit beyond an unsigned int needs a wider PHP integer');
+if (PHP_OS_FAMILY === 'Windows') die('skip an unsigned long is 4 bytes wide on Windows');
+if (getenv('SKIP_SLOW_TESTS')) die('skip slow test');
+?>
+--INI--
+mbstring.regex_retry_limit=4294967296
+--FILE--
+<?php
+/* The limit above is UINT_MAX + 1. It is passed on as an unsigned long, so it
+ * has to be honoured rather than dropped for being out of the range of an
+ * unsigned int. This match needs more retries than the default allows for. */
+$regex = 'A(B|C+)+D|AC+X';
+$str = 'A' . str_repeat('C', 24) . 'X';
+var_dump(mb_ereg($regex, $str));
+var_dump(mb_ereg_match($regex, $str));
+?>
+--EXPECTF--
+Deprecated: Function mb_ereg() is deprecated since 8.6, because the underlying library is no longer maintained in %s on line %d
+bool(true)
+
+Deprecated: Function mb_ereg_match() is deprecated since 8.6, because the underlying library is no longer maintained in %s on line %d
+bool(true)
diff --git a/ext/mysqli/mysqli.c b/ext/mysqli/mysqli.c
index 063abd72e3d..28bf7b8e1b8 100644
--- a/ext/mysqli/mysqli.c
+++ b/ext/mysqli/mysqli.c
@@ -395,7 +395,7 @@ static PHP_INI_MH(OnUpdateDefaultPort)
{
zend_long value = ZEND_ATOL(ZSTR_VAL(new_value));
- if (value < 0 || value > USHRT_MAX) {
+ if (!ZEND_IN_RANGE_OF(value, unsigned short)) {
return FAILURE;
}
diff --git a/ext/openssl/openssl_backend_common.c b/ext/openssl/openssl_backend_common.c
index 762cad3afa7..583f9a7d30b 100644
--- a/ext/openssl/openssl_backend_common.c
+++ b/ext/openssl/openssl_backend_common.c
@@ -2116,7 +2116,7 @@ PHP_OPENSSL_API zend_string* php_openssl_random_pseudo_bytes(zend_long buffer_le
zend_argument_value_error(1, "must be greater than 0");
return NULL;
}
- if (ZEND_LONG_INT_OVFL(buffer_length)) {
+ if (!ZEND_IN_RANGE_OF(buffer_length, int)) {
zend_argument_value_error(1, "must be less than or equal to %d", INT_MAX);
return NULL;
}
diff --git a/ext/openssl/php_openssl_backend.h b/ext/openssl/php_openssl_backend.h
index 364f27eec23..1e43fd79c6b 100644
--- a/ext/openssl/php_openssl_backend.h
+++ b/ext/openssl/php_openssl_backend.h
@@ -63,17 +63,17 @@ typedef X509_EXTENSION PHP_OPENSSL_X509_EXTENSION;
} while(0)
/* check if size_t can be safely casted to int */
#define PHP_OPENSSL_CHECK_SIZE_T_TO_INT(_var, _name, _arg_num) \
- PHP_OPENSSL_CHECK_NUMBER_CONVERSION(ZEND_SIZE_T_INT_OVFL(_var), _name, _arg_num)
+ PHP_OPENSSL_CHECK_NUMBER_CONVERSION(!ZEND_IN_RANGE_OF((size_t)(_var), int), _name, _arg_num)
#define PHP_OPENSSL_CHECK_SIZE_T_TO_INT_NULL_RETURN(_var, _name) \
- PHP_OPENSSL_CHECK_NUMBER_CONVERSION_NULL_RETURN(ZEND_SIZE_T_INT_OVFL(_var), _name)
+ PHP_OPENSSL_CHECK_NUMBER_CONVERSION_NULL_RETURN(!ZEND_IN_RANGE_OF((size_t)(_var), int), _name)
/* check if size_t can be safely casted to unsigned int */
#define PHP_OPENSSL_CHECK_SIZE_T_TO_UINT(_var, _name, _arg_num) \
- PHP_OPENSSL_CHECK_NUMBER_CONVERSION(ZEND_SIZE_T_UINT_OVFL(_var), _name, _arg_num)
+ PHP_OPENSSL_CHECK_NUMBER_CONVERSION(!ZEND_IN_RANGE_OF((size_t)(_var), unsigned int), _name, _arg_num)
/* check if long can be safely casted to int */
#define PHP_OPENSSL_CHECK_LONG_TO_INT(_var, _name, _arg_num) \
- PHP_OPENSSL_CHECK_NUMBER_CONVERSION(ZEND_LONG_EXCEEDS_INT(_var), _name, _arg_num)
+ PHP_OPENSSL_CHECK_NUMBER_CONVERSION(!ZEND_IN_RANGE_OF(_var, int), _name, _arg_num)
#define PHP_OPENSSL_CHECK_LONG_TO_INT_NULL_RETURN(_var, _name) \
- PHP_OPENSSL_CHECK_NUMBER_CONVERSION_NULL_RETURN(ZEND_LONG_EXCEEDS_INT(_var), _name)
+ PHP_OPENSSL_CHECK_NUMBER_CONVERSION_NULL_RETURN(!ZEND_IN_RANGE_OF(_var, int), _name)
/* FIXME: Use the openssl constants instead of
* enum. It is now impossible to match real values
diff --git a/ext/pcntl/pcntl.c b/ext/pcntl/pcntl.c
index 7c8f9d5cc43..87eb1f8ac15 100644
--- a/ext/pcntl/pcntl.c
+++ b/ext/pcntl/pcntl.c
@@ -311,7 +311,7 @@ PHP_FUNCTION(pcntl_alarm)
Z_PARAM_LONG(seconds);
ZEND_PARSE_PARAMETERS_END();
- if (seconds < 0 || seconds > UINT_MAX) {
+ if (!ZEND_IN_RANGE_OF(seconds, unsigned int)) {
zend_argument_value_error(1, "must be between 0 and %u", UINT_MAX);
RETURN_THROWS();
}
diff --git a/ext/pdo_pgsql/pgsql_driver.c b/ext/pdo_pgsql/pgsql_driver.c
index f9d3506a4c8..62742cfb2c1 100644
--- a/ext/pdo_pgsql/pgsql_driver.c
+++ b/ext/pdo_pgsql/pgsql_driver.c
@@ -274,7 +274,7 @@ static void pgsql_handle_closer(pdo_dbh_t *dbh) /* {{{ */
#ifdef HAVE_PG_SET_CHUNKED_ROWS_SIZE
static bool pdo_pgsql_check_chunk_size(zend_long size)
{
- if (size < 0 || ZEND_LONG_EXCEEDS_INT(size)) {
+ if (size < 0 || !ZEND_IN_RANGE_OF(size, int)) {
zend_value_error("Pdo\\Pgsql::ATTR_CHUNK_SIZE must be between 0 and %d", INT_MAX);
return false;
}
diff --git a/ext/pdo_sqlite/sqlite_statement.c b/ext/pdo_sqlite/sqlite_statement.c
index 0d088c99ce7..ef81ef38bb1 100644
--- a/ext/pdo_sqlite/sqlite_statement.c
+++ b/ext/pdo_sqlite/sqlite_statement.c
@@ -273,20 +273,16 @@ static int pdo_sqlite_stmt_get_col(
case SQLITE_INTEGER: {
int64_t i = sqlite3_column_int64(S->stmt, colno);
-#if SIZEOF_ZEND_LONG < 8
- if (i > ZEND_LONG_MAX || i < ZEND_LONG_MIN) {
+ if (!ZEND_IN_RANGE_OF(i, zend_long)) {
const char *text = (const char *) sqlite3_column_text(S->stmt, colno);
if (UNEXPECTED(!text)) {
pdo_sqlite_error_stmt(stmt);
return 0;
}
- ZVAL_STRINGL(result,
- text,
- sqlite3_column_bytes(S->stmt, colno));
- return 1;
+ ZVAL_STRINGL(result, text, sqlite3_column_bytes(S->stmt, colno));
+ } else {
+ ZVAL_LONG(result, i);
}
-#endif
- ZVAL_LONG(result, i);
return 1;
}
diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c
index 9d3bd842cb7..20562aafc78 100644
--- a/ext/phar/phar_object.c
+++ b/ext/phar/phar_object.c
@@ -1360,7 +1360,7 @@ static phar_entry_data *phar_build_entry_data(zend_string *fname, char *path, si
}
/* Sanity check bounds. See GH-14141. */
- if (ZEND_LONG_UINT_OVFL(Z_LVAL(rv))) {
+ if (!ZEND_IN_RANGE_OF(Z_LVAL(rv), uint32_t)) {
*error = estrdup("timestamp is limited to 32-bit");
return NULL;
}
diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c
index 873a7e5ed73..01d764c2ab9 100644
--- a/ext/simplexml/simplexml.c
+++ b/ext/simplexml/simplexml.c
@@ -2249,7 +2249,7 @@ PHP_FUNCTION(simplexml_load_file)
RETURN_THROWS();
}
- if (ZEND_LONG_EXCEEDS_INT(options)) {
+ if (!ZEND_IN_RANGE_OF(options, int)) {
zend_argument_value_error(3, "is too large");
RETURN_THROWS();
}
@@ -2299,15 +2299,15 @@ PHP_FUNCTION(simplexml_load_string)
RETURN_THROWS();
}
- if (ZEND_SIZE_T_INT_OVFL(data_len)) {
+ if (!ZEND_IN_RANGE_OF(data_len, int)) {
zend_argument_value_error(1, "is too long");
RETURN_THROWS();
}
- if (ZEND_SIZE_T_INT_OVFL(ZSTR_LEN(ns))) {
+ if (!ZEND_IN_RANGE_OF(ZSTR_LEN(ns), int)) {
zend_argument_value_error(4, "is too long");
RETURN_THROWS();
}
- if (ZEND_LONG_EXCEEDS_INT(options)) {
+ if (!ZEND_IN_RANGE_OF(options, int)) {
zend_argument_value_error(3, "is too large");
RETURN_THROWS();
}
@@ -2354,15 +2354,15 @@ PHP_METHOD(SimpleXMLElement, __construct)
RETURN_THROWS();
}
- if (ZEND_SIZE_T_INT_OVFL(ZSTR_LEN(data))) {
+ if (!ZEND_IN_RANGE_OF(ZSTR_LEN(data), int)) {
zend_argument_error(zend_ce_exception, 1, "is too long");
RETURN_THROWS();
}
- if (ZEND_SIZE_T_INT_OVFL(ZSTR_LEN(ns))) {
+ if (!ZEND_IN_RANGE_OF(ZSTR_LEN(ns), int)) {
zend_argument_error(zend_ce_exception, 4, "is too long");
RETURN_THROWS();
}
- if (ZEND_LONG_EXCEEDS_INT(options)) {
+ if (!ZEND_IN_RANGE_OF(options, int)) {
zend_argument_error(zend_ce_exception, 2, "is invalid");
RETURN_THROWS();
}
diff --git a/ext/snmp/snmp.c b/ext/snmp/snmp.c
index 6b6c4ed1fc7..7ee40e70e4a 100644
--- a/ext/snmp/snmp.c
+++ b/ext/snmp/snmp.c
@@ -907,7 +907,7 @@ static bool snmp_session_init(php_snmp_session **session_p, int version, zend_st
if (pptr[1] == ':') {
char *pport = pptr + 2;
tmp_port = atoi(pport);
- if (tmp_port < 0 || tmp_port > USHRT_MAX) {
+ if (!ZEND_IN_RANGE_OF(tmp_port, unsigned short)) {
zend_argument_value_error(hostname_arg_num, "remote port must be between 0 and %u", USHRT_MAX);
return false;
}
@@ -922,7 +922,7 @@ static bool snmp_session_init(php_snmp_session **session_p, int version, zend_st
if ((pptr = strchr(host_ptr, ':'))) {
char *pport = pptr + 1;
tmp_port = atoi(pport);
- if (tmp_port < 0 || tmp_port > USHRT_MAX) {
+ if (!ZEND_IN_RANGE_OF(tmp_port, unsigned short)) {
zend_argument_value_error(hostname_arg_num, "remote port must be between 0 and %u", USHRT_MAX);
return false;
}
diff --git a/ext/soap/php_schema.c b/ext/soap/php_schema.c
index d331296eede..2df06c889e5 100644
--- a/ext/soap/php_schema.c
+++ b/ext/soap/php_schema.c
@@ -68,7 +68,7 @@ static int schema_parse_int(const xmlChar *value, const char *name, bool allow_n
}
}
- if (UNEXPECTED(ZEND_LONG_EXCEEDS_INT(lval) || (!allow_negative && lval < 0))) {
+ if (UNEXPECTED(!ZEND_IN_RANGE_OF(lval, int) || (!allow_negative && lval < 0))) {
soap_error1(E_ERROR, "Parsing Schema: %s value is out of range", name);
}
diff --git a/ext/soap/soap.c b/ext/soap/soap.c
index 5c74ae4d20c..2c50aa34605 100644
--- a/ext/soap/soap.c
+++ b/ext/soap/soap.c
@@ -1407,7 +1407,7 @@ PHP_METHOD(SoapServer, handle)
FETCH_THIS_SERVICE(service);
SOAP_GLOBAL(soap_version) = service->version;
- if (arg && ZEND_SIZE_T_INT_OVFL(arg_len)) {
+ if (arg && !ZEND_IN_RANGE_OF(arg_len, int)) {
soap_server_fault_en("Server", "Input string is too long");
SOAP_SERVER_END_CODE();
return;
diff --git a/ext/sockets/conversions.c b/ext/sockets/conversions.c
index 9b36e087e07..01e8283880c 100644
--- a/ext/sockets/conversions.c
+++ b/ext/sockets/conversions.c
@@ -390,7 +390,7 @@ void from_zval_write_int(const zval *arr_value, char *field, ser_context *ctx)
return;
}
- if (lval > INT_MAX || lval < INT_MIN) {
+ if (!ZEND_IN_RANGE_OF(lval, int)) {
do_from_zval_err(ctx, "%s", "given PHP integer is out of bounds "
"for a native int");
return;
@@ -409,7 +409,7 @@ static void from_zval_write_uint32(const zval *arr_value, char *field, ser_conte
return;
}
- if (sizeof(zend_long) > sizeof(uint32_t) && (lval < 0 || lval > 0xFFFFFFFF)) {
+ if (sizeof(zend_long) > sizeof(uint32_t) && !ZEND_IN_RANGE_OF(lval, uint32_t)) {
do_from_zval_err(ctx, "%s", "given PHP integer is out of bounds "
"for an unsigned 32-bit integer");
return;
@@ -428,7 +428,7 @@ static void from_zval_write_net_uint16(const zval *arr_value, char *field, ser_c
return;
}
- if (lval < 0 || lval > 0xFFFF) {
+ if (!ZEND_IN_RANGE_OF(lval, uint16_t)) {
do_from_zval_err(ctx, "%s", "given PHP integer is out of bounds "
"for an unsigned 16-bit integer");
return;
diff --git a/ext/sockets/sendrecvmsg.c b/ext/sockets/sendrecvmsg.c
index a2f697e6fe6..89b593a91e1 100644
--- a/ext/sockets/sendrecvmsg.c
+++ b/ext/sockets/sendrecvmsg.c
@@ -68,7 +68,7 @@ inline ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags)
#define LONG_CHECK_VALID_INT(l, arg_pos) \
do { \
- if ((l) < INT_MIN || (l) > INT_MAX) { \
+ if (!ZEND_IN_RANGE_OF(l, int)) { \
zend_argument_value_error((arg_pos), "must be between %d and %d", INT_MIN, INT_MAX); \
RETURN_THROWS(); \
} \
diff --git a/ext/sockets/sockets.c b/ext/sockets/sockets.c
index 423be987e03..30621c063e2 100644
--- a/ext/sockets/sockets.c
+++ b/ext/sockets/sockets.c
@@ -716,7 +716,7 @@ PHP_FUNCTION(socket_create_listen)
Z_PARAM_LONG(backlog)
ZEND_PARSE_PARAMETERS_END();
- if (port < 0 || port > USHRT_MAX) {
+ if (!ZEND_IN_RANGE_OF(port, unsigned short)) {
zend_argument_value_error(1, "must be between 0 and %u", USHRT_MAX);
RETURN_THROWS();
}
@@ -1307,7 +1307,7 @@ PHP_FUNCTION(socket_strerror)
Z_PARAM_LONG(arg1)
ZEND_PARSE_PARAMETERS_END();
- if (ZEND_LONG_EXCEEDS_INT(arg1)) {
+ if (!ZEND_IN_RANGE_OF(arg1, int)) {
zend_argument_value_error(1, "must be between %d and %d", INT_MIN, INT_MAX);
RETURN_THROWS();
}
@@ -1337,7 +1337,7 @@ PHP_FUNCTION(socket_bind)
php_sock = Z_SOCKET_P(arg1);
ENSURE_SOCKET_VALID(php_sock);
- if (objint < 0 || objint > USHRT_MAX) {
+ if (!ZEND_IN_RANGE_OF(objint, unsigned short)) {
zend_argument_value_error(3, "must be between 0 and %u", USHRT_MAX);
RETURN_THROWS();
}
@@ -1734,7 +1734,7 @@ PHP_FUNCTION(socket_sendto)
#ifdef AF_PACKET
if (php_sock->type != AF_PACKET) {
#endif
- if (port < 0 || port > USHRT_MAX) {
+ if (!ZEND_IN_RANGE_OF(port, unsigned short)) {
zend_argument_value_error(6, "must be between 0 and %u", USHRT_MAX);
RETURN_THROWS();
}
@@ -2169,7 +2169,7 @@ PHP_FUNCTION(socket_set_option)
zend_long timeout = zval_get_long(arg4);
// TCP_USER_TIMEOUT unsigned int
- if (timeout < 0 || timeout > UINT_MAX) {
+ if (!ZEND_IN_RANGE_OF(timeout, unsigned int)) {
zend_argument_value_error(4, "must be between 0 and %u", UINT_MAX);
RETURN_THROWS();
}
@@ -2225,12 +2225,12 @@ PHP_FUNCTION(socket_set_option)
zend_long val_linger = zval_get_long(l_linger);
zend_release_properties(opt_props);
- if (val_lonoff < 0 || val_lonoff > USHRT_MAX) {
+ if (!ZEND_IN_RANGE_OF(val_lonoff, unsigned short)) {
zend_argument_value_error(4, "\"%s\" must be between 0 and %u", l_onoff_key, USHRT_MAX);
RETURN_THROWS();
}
- if (val_linger < 0 || val_linger > USHRT_MAX) {
+ if (!ZEND_IN_RANGE_OF(val_linger, unsigned short)) {
zend_argument_value_error(4, "\"%s\" must be between 0 and %u", l_linger_key, USHRT_MAX);
RETURN_THROWS();
}
@@ -2409,7 +2409,7 @@ PHP_FUNCTION(socket_set_option)
ov = zval_get_long(arg4);
// UDP segmentation offload maximum size or 0 to disable it
- if (ov < 0 || ov > USHRT_MAX) {
+ if (!ZEND_IN_RANGE_OF(ov, unsigned short)) {
zend_argument_value_error(4, "must be between 0 and %u", USHRT_MAX);
RETURN_THROWS();
}
diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c
index 6b9e761e2b4..13e4bbad135 100644
--- a/ext/sqlite3/sqlite3.c
+++ b/ext/sqlite3/sqlite3.c
@@ -615,8 +615,7 @@ static void sqlite_value_to_zval(php_sqlite3_db_object *db_obj, sqlite3_stmt *st
switch (sqlite3_column_type(stmt, column)) {
case SQLITE_INTEGER:
val = sqlite3_column_int64(stmt, column);
-#ifndef ZEND_ENABLE_ZVAL_LONG64
- if (val > ZEND_LONG_MAX || val < ZEND_LONG_MIN) {
+ if (!ZEND_IN_RANGE_OF(val, zend_long)) {
const char *text = (const char *) sqlite3_column_text(stmt, column);
if (UNEXPECTED(text == NULL)) {
php_sqlite3_error(db_obj, SQLITE_NOMEM, "Failed to retrieve column value due to out of memory");
@@ -625,11 +624,8 @@ static void sqlite_value_to_zval(php_sqlite3_db_object *db_obj, sqlite3_stmt *st
ZVAL_STRINGL(data, text, sqlite3_column_bytes(stmt, column));
}
} else {
-#endif
ZVAL_LONG(data, (zend_long) val);
-#ifndef ZEND_ENABLE_ZVAL_LONG64
}
-#endif
break;
case SQLITE_FLOAT:
diff --git a/ext/standard/io_poll.c b/ext/standard/io_poll.c
index ae6d5a4c984..58f9d6d0c92 100644
--- a/ext/standard/io_poll.c
+++ b/ext/standard/io_poll.c
@@ -914,7 +914,7 @@ PHP_METHOD(Io_Poll_Context, wait)
} else if (UNEXPECTED(max_events <= 0)) {
zend_argument_value_error(2, "must be greater than 0");
RETURN_THROWS();
- } else if (ZEND_LONG_INT_OVFL(max_events)) {
+ } else if (!ZEND_IN_RANGE_OF(max_events, int)) {
zend_argument_value_error(2, "must be less than or equal to %d", INT_MAX);
RETURN_THROWS();
}
diff --git a/ext/standard/math.c b/ext/standard/math.c
index ed324f239d2..94f3337405e 100644
--- a/ext/standard/math.c
+++ b/ext/standard/math.c
@@ -349,9 +349,9 @@ PHP_FUNCTION(round)
if (ZEND_NUM_ARGS() >= 2) {
if (precision >= 0) {
- places = ZEND_LONG_INT_OVFL(precision) ? INT_MAX : (int)precision;
+ places = ZEND_IN_RANGE_OF(precision, int) ? (int)precision : INT_MAX;
} else {
- places = ZEND_LONG_INT_UDFL(precision) ? INT_MIN : (int)precision;
+ places = ZEND_IN_RANGE_OF(precision, int) ? (int)precision : INT_MIN;
}
}
@@ -1431,7 +1431,7 @@ PHP_FUNCTION(number_format)
thousand_sep_len = 1;
}
- if (UNEXPECTED(dec > INT_MAX || dec < INT_MIN)) {
+ if (!ZEND_IN_RANGE_OF(dec, int)) {
zend_argument_value_error(2, "must be between %d and %d", INT_MIN, INT_MAX);
RETURN_THROWS();
}
diff --git a/ext/standard/pack.c b/ext/standard/pack.c
index 48f5364d94b..cf2338f9274 100644
--- a/ext/standard/pack.c
+++ b/ext/standard/pack.c
@@ -843,7 +843,7 @@ PHP_FUNCTION(unpack)
long tmp = strtol(format, NULL, 10);
/* There is not strtoi. We have to check the range ourselves.
* With 32-bit long the INT_{MIN,MAX} are useless because long == int, but with 64-bit they do limit us to 32-bit. */
- if (errno || tmp < INT_MIN || tmp > INT_MAX) {
+ if (errno || !ZEND_IN_RANGE_OF(tmp, int)) {
php_error_docref(NULL, E_WARNING, "Type %c: integer overflow", type);
zend_array_destroy(Z_ARR_P(return_value));
RETURN_FALSE;
diff --git a/ext/tidy/tidy.c b/ext/tidy/tidy.c
index 8588a89ddf1..e5900b44811 100644
--- a/ext/tidy/tidy.c
+++ b/ext/tidy/tidy.c
@@ -279,7 +279,7 @@ static void php_tidy_quick_repair(INTERNAL_FUNCTION_PARAMETERS, bool is_file)
data = arg1;
}
- if (ZEND_SIZE_T_UINT_OVFL(ZSTR_LEN(data))) {
+ if (!ZEND_IN_RANGE_OF(ZSTR_LEN(data), unsigned int)) {
if (is_file) {
zend_string_release_ex(data, false);
zend_argument_value_error(1, "File content is too long");
@@ -833,7 +833,7 @@ static zend_result php_tidy_parse_string(PHPTidyObj *obj, const zend_string *str
{
TidyBuffer buf;
- ZEND_ASSERT(!ZEND_SIZE_T_UINT_OVFL(ZSTR_LEN(string)));
+ ZEND_ASSERT(ZEND_IN_RANGE_OF(ZSTR_LEN(string), unsigned int));
if (enc) {
if (tidySetCharEncoding(obj->ptdoc->doc, enc) < 0) {
@@ -992,7 +992,7 @@ static zend_result php_tidy_output_handler(void **nothing, php_output_context *o
TidyBuffer inbuf, outbuf, errbuf;
if (TG(clean_output) && (output_context->op & PHP_OUTPUT_HANDLER_START) && (output_context->op & PHP_OUTPUT_HANDLER_FINAL)) {
- if (ZEND_SIZE_T_UINT_OVFL(output_context->in.used)) {
+ if (!ZEND_IN_RANGE_OF(output_context->in.used, unsigned int)) {
php_error_docref(NULL, E_WARNING, "Input string is too long");
return status;
}
@@ -1043,7 +1043,7 @@ PHP_FUNCTION(tidy_parse_string)
Z_PARAM_STRING_OR_NULL(enc, enc_len)
ZEND_PARSE_PARAMETERS_END();
- if (ZEND_SIZE_T_UINT_OVFL(ZSTR_LEN(input))) {
+ if (!ZEND_IN_RANGE_OF(ZSTR_LEN(input), unsigned int)) {
zend_argument_value_error(1, "is too long");
RETURN_THROWS();
}
@@ -1110,7 +1110,7 @@ PHP_FUNCTION(tidy_parse_file)
RETURN_FALSE;
}
- if (ZEND_SIZE_T_UINT_OVFL(ZSTR_LEN(contents))) {
+ if (!ZEND_IN_RANGE_OF(ZSTR_LEN(contents), unsigned int)) {
zend_string_release_ex(contents, 0);
zend_value_error("File content is too long");
RETURN_THROWS();
@@ -1390,7 +1390,7 @@ PHP_METHOD(tidy, __construct)
RETURN_THROWS();
}
- if (ZEND_SIZE_T_UINT_OVFL(ZSTR_LEN(contents))) {
+ if (!ZEND_IN_RANGE_OF(ZSTR_LEN(contents), unsigned int)) {
zend_string_release_ex(contents, 0);
zend_value_error("File content is too long");
RETURN_THROWS();
@@ -1435,7 +1435,7 @@ PHP_METHOD(tidy, parseFile)
RETURN_FALSE;
}
- if (ZEND_SIZE_T_UINT_OVFL(ZSTR_LEN(contents))) {
+ if (!ZEND_IN_RANGE_OF(ZSTR_LEN(contents), unsigned int)) {
zend_string_release_ex(contents, 0);
zend_value_error("File content is too long");
RETURN_THROWS();
@@ -1462,7 +1462,7 @@ PHP_METHOD(tidy, parseString)
Z_PARAM_STRING_OR_NULL(enc, enc_len)
ZEND_PARSE_PARAMETERS_END();
- if (ZEND_SIZE_T_UINT_OVFL(ZSTR_LEN(input))) {
+ if (!ZEND_IN_RANGE_OF(ZSTR_LEN(input), unsigned int)) {
zend_argument_value_error(1, "is too long");
RETURN_THROWS();
}
diff --git a/ext/zend_test/test.c b/ext/zend_test/test.c
index c4918a18314..28cacadff29 100644
--- a/ext/zend_test/test.c
+++ b/ext/zend_test/test.c
@@ -1235,8 +1235,8 @@ static ZEND_FUNCTION(zend_test_call_with_consumed_args)
Z_PARAM_LONG(consumed_args)
ZEND_PARSE_PARAMETERS_END();
- if (UNEXPECTED(consumed_args < 0 || consumed_args > UINT32_MAX)) {
- zend_argument_value_error(3, "must be between 0 and 4294967295");
+ if (!ZEND_IN_RANGE_OF(consumed_args, uint32_t)) {
+ zend_argument_value_error(3, "must be between 0 and %u", UINT32_MAX);
RETURN_THROWS();
}
diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c
index a278a3d6ac8..320da1143c6 100644
--- a/ext/zip/php_zip.c
+++ b/ext/zip/php_zip.c
@@ -431,7 +431,7 @@ static zend_result php_zip_parse_options(HashTable *options, zip_options *opts)
zend_type_error("Option \"comp_flags\" must be of type int, %s given", zend_zval_value_name(option));
return FAILURE;
}
- if (tmp < 0 || tmp > USHRT_MAX) {
+ if (!ZEND_IN_RANGE_OF(tmp, unsigned short)) {
php_error_docref(NULL, E_WARNING, "Option \"comp_flags\" must be between 0 and %u", USHRT_MAX);
}
opts->comp_flags = (zip_uint32_t)tmp;
@@ -2691,7 +2691,7 @@ PHP_METHOD(ZipArchive, setCompressionName)
RETURN_THROWS();
}
- if (comp_flags < 0 || comp_flags > USHRT_MAX) {
+ if (!ZEND_IN_RANGE_OF(comp_flags, unsigned short)) {
// comp_flags is cast down accordingly in libzip, zip_entry_t compression_level is of zip_uint16_t
zend_argument_value_error(3, "must be between 0 and %u", USHRT_MAX);
RETURN_THROWS();
@@ -2736,7 +2736,7 @@ PHP_METHOD(ZipArchive, setCompressionIndex)
RETURN_THROWS();
}
- if (comp_flags < 0 || comp_flags > USHRT_MAX) {
+ if (!ZEND_IN_RANGE_OF(comp_flags, unsigned short)) {
// comp_flags is cast down accordingly in libzip, zip_entry_t compression_level is of zip_uint16_t
zend_argument_value_error(3, "must be between 0 and %u", USHRT_MAX);
RETURN_THROWS();
@@ -3440,7 +3440,7 @@ PHP_METHOD(ZipArchive, isEncryptionMethodSupported)
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|b", &method, &enc) == FAILURE) {
return;
}
- if (method < 0 || method > USHRT_MAX) {
+ if (!ZEND_IN_RANGE_OF(method, unsigned short)) {
zend_argument_value_error(1, "must be between 0 and %u", USHRT_MAX);
RETURN_THROWS();
}
diff --git a/win32/codepage.c b/win32/codepage.c
index 1a723efa449..61020ce989e 100644
--- a/win32/codepage.c
+++ b/win32/codepage.c
@@ -597,8 +597,8 @@ PHP_FUNCTION(sapi_windows_cp_set)
RETURN_THROWS();
}
- if (ZEND_LONG_UINT_OVFL(id)) {
- zend_argument_value_error(1, "must be between 0 and %u", UINT_MAX);
+ if (!ZEND_IN_RANGE_OF(id, DWORD)) {
+ zend_argument_value_error(1, "must be between 0 and %u", MAXDWORD);
RETURN_THROWS();
}
@@ -669,7 +669,7 @@ PHP_FUNCTION(sapi_windows_cp_conv)
Z_PARAM_STR(subject)
ZEND_PARSE_PARAMETERS_END();
- if (ZEND_SIZE_T_INT_OVFL(ZSTR_LEN(subject))) {
+ if (!ZEND_IN_RANGE_OF(ZSTR_LEN(subject), int)) {
zend_argument_value_error(1, "is too long");
RETURN_THROWS();
}
@@ -681,8 +681,8 @@ PHP_FUNCTION(sapi_windows_cp_conv)
RETURN_THROWS();
}
} else {
- if (ZEND_LONG_UINT_OVFL(int_in_codepage)) {
- zend_argument_value_error(1, "must be between 0 and %u", UINT_MAX);
+ if (!ZEND_IN_RANGE_OF(int_in_codepage, DWORD)) {
+ zend_argument_value_error(1, "must be between 0 and %u", MAXDWORD);
RETURN_THROWS();
}
@@ -700,8 +700,8 @@ PHP_FUNCTION(sapi_windows_cp_conv)
RETURN_THROWS();
}
} else {
- if (ZEND_LONG_UINT_OVFL(int_out_codepage)) {
- zend_argument_value_error(2, "must be between 0 and %u", UINT_MAX);
+ if (!ZEND_IN_RANGE_OF(int_out_codepage, DWORD)) {
+ zend_argument_value_error(2, "must be between 0 and %u", MAXDWORD);
RETURN_THROWS();
}