[php-src] master: ext/intl: Fix intl_error_name() truncating codes outside the int range
| From: | lacatoire via David Carlier | Date: | Fri, 20 Nov 2026 15:47:36 +0000 |
| Subject: | [php-src] master: ext/intl: Fix intl_error_name() truncating codes outside the int range | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-143972@lists.php.net to get a copy of this message | ||
Author: lacatoire (lacatoire)
Committer: David Carlier (devnexen)
Date: 2026-11-20T15:45:50Z
Commit: https://github.com/php/php-src/commit/89dae889a621d8a2eccc7a8646ea067c33ac653b
Raw diff: https://github.com/php/php-src/commit/89dae889a621d8a2eccc7a8646ea067c33ac653b.diff
ext/intl: Fix intl_error_name() truncating codes outside the int range
Close GH-25594
Changed paths:
A ext/intl/tests/intl_error_name_out_of_range.phpt
M NEWS
M ext/intl/common/common_error.c
Diff:
diff --git a/NEWS b/NEWS
index ed8b3711ebef..70d1c4221e93 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 733a1913ad08..45b49519914b 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 000000000000..4b1d0834c6a0
--- /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"