From d0c7cac27193005e94ec6211592f62ed7b0c93dc Mon Sep 17 00:00:00 2001 From: Simon Montagu Date: Sun, 25 Jan 2009 12:10:31 +0200 Subject: [PATCH] Tests for Unicode security issues -- bug 445886 --- intl/uconv/tests/Makefile.in | 4 + .../test_unicode_noncharacterescapes.html | 302 +++++++++++++++++ .../test_unicode_noncharacters_gb18030.html | 304 ++++++++++++++++++ .../test_unicode_noncharacters_utf8.html | 302 +++++++++++++++++ .../tests/test_utf8_overconsumption.html | 38 +++ intl/uconv/tests/unit/test_utf8_illegals.js | 77 +++++ 6 files changed, 1027 insertions(+) create mode 100644 intl/uconv/tests/test_unicode_noncharacterescapes.html create mode 100644 intl/uconv/tests/test_unicode_noncharacters_gb18030.html create mode 100644 intl/uconv/tests/test_unicode_noncharacters_utf8.html create mode 100644 intl/uconv/tests/test_utf8_overconsumption.html create mode 100644 intl/uconv/tests/unit/test_utf8_illegals.js diff --git a/intl/uconv/tests/Makefile.in b/intl/uconv/tests/Makefile.in index b08411db4094..4169f4dd7da4 100644 --- a/intl/uconv/tests/Makefile.in +++ b/intl/uconv/tests/Makefile.in @@ -73,6 +73,10 @@ relativesrcdir = intl/uconv/tests _TEST_FILES = \ test_bug335816.html \ + test_unicode_noncharacterescapes.html \ + test_unicode_noncharacters_gb18030.html \ + test_unicode_noncharacters_utf8.html \ + test_utf8_overconsumption.html \ $(NULL) libs:: $(_TEST_FILES) $(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir) diff --git a/intl/uconv/tests/test_unicode_noncharacterescapes.html b/intl/uconv/tests/test_unicode_noncharacterescapes.html new file mode 100644 index 000000000000..c0005e6a4205 --- /dev/null +++ b/intl/uconv/tests/test_unicode_noncharacterescapes.html @@ -0,0 +1,302 @@ + + + + + + Test for Unicode non-characters + + + + + +
+
+
+Mozilla Bug 445886 +

All good.

+ + + diff --git a/intl/uconv/tests/test_unicode_noncharacters_gb18030.html b/intl/uconv/tests/test_unicode_noncharacters_gb18030.html new file mode 100644 index 000000000000..bbbbf3747397 --- /dev/null +++ b/intl/uconv/tests/test_unicode_noncharacters_gb18030.html @@ -0,0 +1,304 @@ + + + + + + Test for Unicode non-characters + + + + + +

+
+Mozilla Bug +445886 +

All good.

+ + + diff --git a/intl/uconv/tests/test_unicode_noncharacters_utf8.html b/intl/uconv/tests/test_unicode_noncharacters_utf8.html new file mode 100644 index 000000000000..07dc0f4e19af --- /dev/null +++ b/intl/uconv/tests/test_unicode_noncharacters_utf8.html @@ -0,0 +1,302 @@ + + + + + + Test for Unicode non-characters + + + + + +
+
+
+Mozilla Bug 445886 +

All good.

+ + + diff --git a/intl/uconv/tests/test_utf8_overconsumption.html b/intl/uconv/tests/test_utf8_overconsumption.html new file mode 100644 index 000000000000..db9ede2ecf76 --- /dev/null +++ b/intl/uconv/tests/test_utf8_overconsumption.html @@ -0,0 +1,38 @@ + + + + + + Test for Unicode non-characters + + + + + +onload="Inject()"> +
+
+
+Mozilla Bug 445886 +

All good.

+ + + diff --git a/intl/uconv/tests/unit/test_utf8_illegals.js b/intl/uconv/tests/unit/test_utf8_illegals.js new file mode 100644 index 000000000000..f54073726a64 --- /dev/null +++ b/intl/uconv/tests/unit/test_utf8_illegals.js @@ -0,0 +1,77 @@ +// Tests illegal UTF-8 sequences + +const Cc = Components.Constructor; +const Ci = Components.interfaces; + +const inStrings1 = new Array("%c0%af", // long forms of 0x2F + "%e0%80%af", + "%f0%80%80%af", + "%f8%80%80%80%af", + "%fc%80%80%80%80%af", + // lone surrogates + "%ed%a0%80", // D800 + "%ed%ad%bf", // DB7F + "%ed%ae%80", // DB80 + "%ed%af%bf", // DBFF + "%ed%b0%80", // DC00 + "%ed%be%80", // DF80 + "%ed%bf%bf"); // DFFF +const expected1 = "ABC\ufffdXYZ"; + // Surrogate pairs +const inStrings2 = new Array("%ed%a0%80%ed%b0%80", // D800 DC00 + "%ed%a0%80%ed%bf%bf", // D800 DFFF + "%ed%ad%bf%ed%b0%80", // DB7F DC00 + "%ed%ad%bf%ed%bf%bf", // DB7F DFFF + "%ed%ae%80%ed%b0%80", // DB80 DC00 + "%ed%ae%80%ed%bf%bf", // DB80 DFFF + "%ed%af%bf%ed%b0%80", // DBFF DC00 + "%ed%ad%bf%ed%bf%bf"); // DBFF DFFF +const expected2 = "ABC\ufffd\ufffdXYZ"; + +function testCaseInputStream(inStr, expected) +{ + var dataURI = "data:text/plain; charset=UTF-8,ABC" + inStr + "XYZ" + dump(inStr + "==>"); + + var IOService = Cc("@mozilla.org/network/io-service;1", + "nsIIOService"); + var ConverterInputStream = + Cc("@mozilla.org/intl/converter-input-stream;1", + "nsIConverterInputStream", + "init"); + + var ios = new IOService(); + var channel = ios.newChannel(dataURI, "", null); + var testInputStream = channel.open(); + var testConverter = new ConverterInputStream(testInputStream, + "UTF-8", + 16, + 0xFFFD); + + if (!(testConverter instanceof Ci.nsIUnicharLineInputStream)) + throw "not line input stream"; + + var outStr = ""; + var more; + do { + // read the line and check for eof + var line = {}; + more = testConverter.readLine(line); + outStr += line.value; + } while (more); + + dump(outStr + "; expected=" + expected + "\n"); + do_check_eq(outStr, expected); + do_check_eq(outStr.length, expected.length); +} + +function run_test() { + for (var i = 0; i < inStrings1.length; ++i) { + var inStr = inStrings1[i]; + testCaseInputStream(inStr, expected1); + } + for (var i = 0; i < inStrings2.length; ++i) { + var inStr = inStrings2[i]; + testCaseInputStream(inStr, expected2); + } +}