]> granicus.if.org Git - libexpat/commitdiff
Test top-bit-set character mimicking surrogate high is rejected
authorRhodri James <rhodri@kynesim.co.uk>
Fri, 9 Jun 2017 16:05:38 +0000 (17:05 +0100)
committerSebastian Pipping <sebastian@pipping.org>
Sat, 22 Jul 2017 20:49:18 +0000 (22:49 +0200)
expat/tests/runtests.c

index c9fed21a28b0e00cb9a6e0ceedaa9788ee3aa995..cb660db82754c2f85cc87c3ff51463949e32d308 100644 (file)
@@ -5297,7 +5297,8 @@ MiscEncodingHandler(void *data,
     if (!strcmp(encoding, "invalid-9") ||
         !strcmp(encoding, "ascii-like") ||
         !strcmp(encoding, "invalid-len") ||
-        !strcmp(encoding, "invalid-a"))
+        !strcmp(encoding, "invalid-a") ||
+        !strcmp(encoding, "invalid-surrogate"))
         high_map = -1;
 
     for (i = 0; i < 128; ++i)
@@ -5314,6 +5315,11 @@ MiscEncodingHandler(void *data,
     /* If required, make a top-bit set character a valid ASCII character */
     if (!strcmp(encoding, "invalid-a"))
         info->map[0x82] = 'a';
+    /* If required, give a top-bit set character a forbidden value,
+     * what would otherwise be the first of a surrogate pair.
+     */
+    if (!strcmp(encoding, "invalid-surrogate"))
+        info->map[0x83] = 0xd801;
 
     info->data = data;
     info->release = NULL;
@@ -5507,6 +5513,18 @@ START_TEST(test_unknown_encoding_invalid_topbit)
 }
 END_TEST
 
+START_TEST(test_unknown_encoding_invalid_surrogate)
+{
+    const char *text =
+        "<?xml version='1.0' encoding='invalid-surrogate'?>\n"
+        "<doc>Hello, \x82 world</doc>";
+
+    XML_SetUnknownEncodingHandler(parser, MiscEncodingHandler, NULL);
+    expect_failure(text, XML_ERROR_INVALID_TOKEN,
+                   "Invalid unknown encoding not faulted");
+}
+END_TEST
+
 
 /*
  * Namespaces tests.
@@ -10776,6 +10794,7 @@ make_suite(void)
     tcase_add_test(tc_basic, test_unknown_ascii_encoding_fail);
     tcase_add_test(tc_basic, test_unknown_encoding_invalid_length);
     tcase_add_test(tc_basic, test_unknown_encoding_invalid_topbit);
+    tcase_add_test(tc_basic, test_unknown_encoding_invalid_surrogate);
 
     suite_add_tcase(s, tc_namespace);
     tcase_add_checked_fixture(tc_namespace,