From 67aabeb2b8a7b1cf1bf362a42af671931662c9be Mon Sep 17 00:00:00 2001 From: Rhodri James Date: Fri, 9 Jun 2017 16:35:57 +0100 Subject: [PATCH] Test top-bit set character mimicking ASCII is rejected in encodings --- expat/tests/runtests.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/expat/tests/runtests.c b/expat/tests/runtests.c index a5c436a1..c9fed21a 100644 --- a/expat/tests/runtests.c +++ b/expat/tests/runtests.c @@ -5296,7 +5296,8 @@ MiscEncodingHandler(void *data, if (!strcmp(encoding, "invalid-9") || !strcmp(encoding, "ascii-like") || - !strcmp(encoding, "invalid-len")) + !strcmp(encoding, "invalid-len") || + !strcmp(encoding, "invalid-a")) high_map = -1; for (i = 0; i < 128; ++i) @@ -5310,6 +5311,9 @@ MiscEncodingHandler(void *data, /* If required, have a top-bit set character starts a 5-byte sequence */ if (!strcmp(encoding, "invalid-len")) info->map[0x81] = -5; + /* If required, make a top-bit set character a valid ASCII character */ + if (!strcmp(encoding, "invalid-a")) + info->map[0x82] = 'a'; info->data = data; info->release = NULL; @@ -5491,6 +5495,18 @@ START_TEST(test_unknown_encoding_invalid_length) } END_TEST +START_TEST(test_unknown_encoding_invalid_topbit) +{ + const char *text = + "\n" + "Hello, world"; + + XML_SetUnknownEncodingHandler(parser, MiscEncodingHandler, NULL); + expect_failure(text, XML_ERROR_UNKNOWN_ENCODING, + "Invalid unknown encoding not faulted"); +} +END_TEST + /* * Namespaces tests. @@ -10759,6 +10775,7 @@ make_suite(void) tcase_add_test(tc_basic, test_unknown_ascii_encoding_ok); 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); suite_add_tcase(s, tc_namespace); tcase_add_checked_fixture(tc_namespace, -- 2.40.0