Commit 89dae889a62 for php
commit 89dae889a621d8a2eccc7a8646ea067c33ac653b
Author: lacatoire <la.catoire@gmail.com>
Date: Thu Nov 19 16:38:05 2026 +0100
ext/intl: Fix intl_error_name() truncating codes outside the int range
Close GH-25594
diff --git a/NEWS b/NEWS
index ed8b3711ebe..70d1c4221e9 100644
--- a/NEWS
+++ b/NEWS
@@ -69,6 +69,8 @@ PHP NEWS
- Intl:
. Fixed Locale::lookup() ignoring the default locale when the language tag
list is empty. (Weilin Du)
+ . Fixed intl_error_name() truncating error codes outside the int range.
+ (lacatoire)
- JSON:
. Fixed json_decode() and json_validate() error messages. (lacatoire)
diff --git a/ext/intl/common/common_error.c b/ext/intl/common/common_error.c
index 733a1913ad0..45b49519914 100644
--- a/ext/intl/common/common_error.c
+++ b/ext/intl/common/common_error.c
@@ -65,6 +65,10 @@ PHP_FUNCTION( intl_error_name )
Z_PARAM_LONG(err_code)
ZEND_PARSE_PARAMETERS_END();
+ if (err_code < INT32_MIN || err_code > INT32_MAX) {
+ err_code = INT32_MAX;
+ }
+
RETURN_STRING( (char*)u_errorName( err_code ) );
}
/* }}} */
diff --git a/ext/intl/tests/intl_error_name_out_of_range.phpt b/ext/intl/tests/intl_error_name_out_of_range.phpt
new file mode 100644
index 00000000000..4b1d0834c6a
--- /dev/null
+++ b/ext/intl/tests/intl_error_name_out_of_range.phpt
@@ -0,0 +1,20 @@
+--TEST--
+intl_error_name(): a code outside the int range is not truncated
+--EXTENSIONS--
+intl
+--FILE--
+<?php
+var_dump(intl_error_name(2**32));
+var_dump(intl_error_name(2**32 + 1));
+var_dump(intl_error_name(-(2**32) + 1));
+var_dump(intl_error_name(PHP_INT_MIN));
+var_dump(intl_error_name(2**31));
+var_dump(intl_error_name(0));
+?>
+--EXPECT--
+string(18) "[BOGUS UErrorCode]"
+string(18) "[BOGUS UErrorCode]"
+string(18) "[BOGUS UErrorCode]"
+string(18) "[BOGUS UErrorCode]"
+string(18) "[BOGUS UErrorCode]"
+string(12) "U_ZERO_ERROR"