Skip to content

Commit 76e249d

Browse files
committed
Partially fix #72506: idn_to_ascii for UTS #46 incorrect for long domain names
We don't actually fix this issue wrt. the empty $info array, because it is not clear what this array should contain and we're concerned about the potential BC break, but at least we fix the inconsistent handling of resulting domains with 255 bytes (which raise an error), and longer domains (which just return FALSE), what has to be considered a very minor BC break if at all.
1 parent 17d4f5c commit 76e249d

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ PHP NEWS
2323
. Fixed bug #72575 (using --allow-to-run-as-root should ignore missing user).
2424
(gooh)
2525

26+
- Intl:
27+
. Partially fixed #72506 (idn_to_ascii for UTS #46 incorrect for long domain
28+
names). (cmb)
29+
2630
- PDO:
2731
. Fixed bug #52384 (Adds bound parameter value to PDOStatement::debugDumpParams).
2832
(bishopb)

ext/intl/idn/idn.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,12 @@ static void php_intl_idn_to_46(INTERNAL_FUNCTION_PARAMETERS,
158158
len = uidna_nameToUnicodeUTF8(uts46, domain, (int32_t)domain_len,
159159
buffer, buffer_capac, &info, &status);
160160
}
161-
if (php_intl_idn_check_status(status, "failed to convert name",
161+
if (len >= 255 || php_intl_idn_check_status(status, "failed to convert name",
162162
mode TSRMLS_CC) == FAILURE) {
163163
uidna_close(uts46);
164164
efree(buffer);
165165
RETURN_FALSE;
166166
}
167-
if (len >= 255) {
168-
php_error_docref(NULL TSRMLS_CC, E_ERROR, "ICU returned an unexpected length");
169-
}
170167

171168
buffer[len] = '\0';
172169

ext/intl/tests/bug72506.phpt

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--TEST--
2+
Bug #72506 (idn_to_ascii with INTL_IDNA_VARIANT_UTS46 fatals for long domain names)
3+
--DESCRIPTION--
4+
Actually, the $info array should be populated for these cases, but at least it's
5+
not clear yet with which values exactly.
6+
--SKIPIF--
7+
<?php
8+
if (!extension_loaded('intl')) die('skip this test requires ext/intl');
9+
if (!defined('INTL_IDNA_VARIANT_UTS46')) die('skip no UTS #46 API');
10+
?>
11+
--FILE--
12+
<?php
13+
// ASCII domain name with 255 characters
14+
$domain = str_repeat('a.', 126) . 'aaa';
15+
$result = idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46, $info);
16+
var_dump($result, $info);
17+
18+
// ASCII domain name with 256 characters – one character added
19+
$domain .= 'a';
20+
$result = idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46, $info);
21+
var_dump($result, $info);
22+
23+
// International domain name with cyrillic "ф" characters
24+
$domain = str_repeat('ф.', 32) . 'a';
25+
$result = idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46, $info);
26+
var_dump($result, $info);
27+
?>
28+
--EXPECT--
29+
bool(false)
30+
array(0) {
31+
}
32+
bool(false)
33+
array(0) {
34+
}
35+
bool(false)
36+
array(0) {
37+
}

0 commit comments

Comments
 (0)