From fdb606f75eec211e9ff3f98a6e09ceebce83f720 Mon Sep 17 00:00:00 2001 From: lacatoire Date: Tue, 24 Nov 2026 14:17:33 +0100 Subject: [PATCH 1/2] ext/iconv: use a larger buffer in _php_iconv_strlen() --- ext/iconv/iconv.c | 3 ++- ext/iconv/tests/strlen_large_string.phpt | 28 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 ext/iconv/tests/strlen_large_string.phpt diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c index 98cac27a6804..500c766ecc14 100644 --- a/ext/iconv/iconv.c +++ b/ext/iconv/iconv.c @@ -575,7 +575,8 @@ fail:; /* {{{ _php_iconv_strlen() */ static php_iconv_err_t _php_iconv_strlen(size_t *pretval, const char *str, size_t nbytes, const char *enc) { - char buf[GENERIC_SUPERSET_NBYTES*2]; + /* A multiple of GENERIC_SUPERSET_NBYTES, large enough to keep the number of iconv() calls low */ + char buf[GENERIC_SUPERSET_NBYTES * 1024]; php_iconv_err_t err = PHP_ICONV_ERR_SUCCESS; diff --git a/ext/iconv/tests/strlen_large_string.phpt b/ext/iconv/tests/strlen_large_string.phpt new file mode 100644 index 000000000000..b71bf40fe710 --- /dev/null +++ b/ext/iconv/tests/strlen_large_string.phpt @@ -0,0 +1,28 @@ +--TEST-- +iconv_strlen(), iconv_substr(): strings around and beyond the conversion buffer size +--EXTENSIONS-- +iconv +--FILE-- + +--EXPECTF-- +string(6) "ééé" +string(6) "ééé" +int(4) + +Notice: iconv_strlen(): Detected an illegal character in input string in %s on line %d +bool(false) From 3d1ee0eb13a4aa5604e7d4f82a6687d298c562a1 Mon Sep 17 00:00:00 2001 From: lacatoire Date: Tue, 24 Nov 2026 18:47:02 +0100 Subject: [PATCH 2/2] ext/iconv: shorten iconv_substr() checks in strlen_large_string.phpt --- ext/iconv/tests/strlen_large_string.phpt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/iconv/tests/strlen_large_string.phpt b/ext/iconv/tests/strlen_large_string.phpt index b71bf40fe710..f4347ad96e0c 100644 --- a/ext/iconv/tests/strlen_large_string.phpt +++ b/ext/iconv/tests/strlen_large_string.phpt @@ -13,7 +13,7 @@ foreach (["a", "é", "€", "𝄞"] as $char) { } } -$string = str_repeat("é", 1000000); +$string = str_repeat("é", 2046) . "abc"; var_dump(iconv_substr($string, 5, 3, "UTF-8")); var_dump(iconv_substr($string, -3, 3, "UTF-8")); var_dump(iconv_strlen("aé€𝄞", "UTF-8")); @@ -21,7 +21,7 @@ var_dump(iconv_strlen(str_repeat("é", 1500) . "\xFF", "UTF-8")); ?> --EXPECTF-- string(6) "ééé" -string(6) "ééé" +string(3) "abc" int(4) Notice: iconv_strlen(): Detected an illegal character in input string in %s on line %d