Skip to content

Commit b9ca573

Browse files
committed
Fixed bug #76829 Incorrect validation of domain on idn_to_utf8() function
As stated by RFC 5890, U-Labels might be up to 252 Unicode code points long. This can be fixed in 7.1+ as well, but there might potentially be issues in some existing apps expecting the output to be max 255 octets long. Thus it seems to be safer to not to touch stable branches.
1 parent 3f2a3c5 commit b9ca573

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

ext/intl/idn/idn.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static void php_intl_idn_to_46(INTERNAL_FUNCTION_PARAMETERS,
138138
UErrorCode status = U_ZERO_ERROR;
139139
UIDNA *uts46;
140140
int32_t len;
141-
int32_t buffer_capac = 255; /* no domain name may exceed this */
141+
int32_t buffer_capac = 252*4; /* no domain name may exceed this */
142142
zend_string *buffer = zend_string_alloc(buffer_capac, 0);
143143
UIDNAInfo info = UIDNA_INFO_INITIALIZER;
144144
int buffer_used = 0;
@@ -156,7 +156,7 @@ static void php_intl_idn_to_46(INTERNAL_FUNCTION_PARAMETERS,
156156
len = uidna_nameToUnicodeUTF8(uts46, ZSTR_VAL(domain), ZSTR_LEN(domain),
157157
ZSTR_VAL(buffer), buffer_capac, &info, &status);
158158
}
159-
if (len >= 255 || php_intl_idn_check_status(status, "failed to convert name") == FAILURE) {
159+
if (len >= 252*4 || php_intl_idn_check_status(status, "failed to convert name") == FAILURE) {
160160
uidna_close(uts46);
161161
zend_string_efree(buffer);
162162
RETURN_FALSE;

ext/intl/tests/idn_bug76829.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Bug #76829 Incorrect validation of domain on idn_to_utf8() function
3+
--SKIPIF--
4+
<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
5+
--FILE--
6+
<?php
7+
8+
$punycode = idn_to_ascii('абвгдаежзи.абвгдаежзи.абвгдаежзи.абвгдаежзи.абвгдаежзи.абвгдаежзи.абвгдаежзи.абвгдаежзи.абвгдаежзи.абвгдаежзи.абвгдаежзи.абвгдаежзи.абвгдаежзи.абвгдаеж.рф', IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46);
9+
10+
$unicode = idn_to_utf8($punycode, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46);
11+
12+
var_dump($unicode);
13+
14+
?>
15+
--EXPECT--
16+
string(294) "абвгдаежзи.абвгдаежзи.абвгдаежзи.абвгдаежзи.абвгдаежзи.абвгдаежзи.абвгдаежзи.абвгдаежзи.абвгдаежзи.абвгдаежзи.абвгдаежзи.абвгдаежзи.абвгдаежзи.абвгдаеж.рф"

0 commit comments

Comments
 (0)