Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ext/iconv/iconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
28 changes: 28 additions & 0 deletions ext/iconv/tests/strlen_large_string.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--TEST--
iconv_strlen(), iconv_substr(): strings around and beyond the conversion buffer size
--EXTENSIONS--
iconv
--FILE--
<?php
foreach (["a", "é", "€", "𝄞"] as $char) {
foreach ([0, 1, 1023, 1024, 1025, 2048, 2049, 1000000] as $count) {
$string = str_repeat($char, $count);
if (iconv_strlen($string, "UTF-8") !== $count) {
echo "iconv_strlen() mismatch for $count x $char\n";
}
}
}

$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"));
var_dump(iconv_strlen(str_repeat("é", 1500) . "\xFF", "UTF-8"));
?>
--EXPECTF--
string(6) "ééé"
string(3) "abc"
int(4)

Notice: iconv_strlen(): Detected an illegal character in input string in %s on line %d
bool(false)
Loading