Skip to content

Commit 42e44ef

Browse files
narayankandi34
authored andcommitted
IDN: Fix handling of long domain names.
We were incorrectly using sizeof() to calculate the size of the output array. Note that this change also changes the output size to 512 to minimize behavioural differences (especially wrt. ICU checks on sizes). bug: 30765246 Change-Id: I5d28ddc45d2d6d2bed3e479ca195ed2779b906ed (cherry picked from commit fffeb3b)
1 parent 30d2012 commit 42e44ef

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

luni/src/main/native/libcore_icu_NativeIDN.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@ static jstring NativeIDN_convertImpl(JNIEnv* env, jclass, jstring javaSrc, jint
3737
if (src.get() == NULL) {
3838
return NULL;
3939
}
40-
UChar dst[256];
40+
static const size_t kDstSize = 512;
41+
UChar dst[kDstSize];
4142
UErrorCode status = U_ZERO_ERROR;
4243
size_t resultLength = toAscii
43-
? uidna_IDNToASCII(src.get(), src.size(), &dst[0], sizeof(dst), flags, NULL, &status)
44-
: uidna_IDNToUnicode(src.get(), src.size(), &dst[0], sizeof(dst), flags, NULL, &status);
44+
? uidna_IDNToASCII(src.get(), src.size(), &dst[0], kDstSize, flags, NULL, &status)
45+
: uidna_IDNToUnicode(src.get(), src.size(), &dst[0], kDstSize, flags, NULL, &status);
4546
if (U_FAILURE(status)) {
4647
jniThrowException(env, "java/lang/IllegalArgumentException", u_errorName(status));
4748
return NULL;

luni/src/test/java/libcore/java/net/IDNTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,15 @@ public void test_toUnicode_failures() {
3737
String longInput = makePunyString(512);
3838
assertEquals(longInput, IDN.toUnicode(longInput));
3939
}
40+
41+
// http://b/30765246
42+
public void testLongDomainName() {
43+
String label63 = "123456789-123456789-123456789-123456789-123456789-123456789-123";
44+
String host255 = label63 + "." + label63 + "." + label63 + "." + label63;
45+
try {
46+
IDN.toASCII(host255.substring(3) + ".com");
47+
fail();
48+
} catch (IllegalArgumentException expected) {
49+
}
50+
}
4051
}

0 commit comments

Comments
 (0)