Test parsing a PI with a failing allocator
@@ -3752,6 +3752,44 @@ alloc_teardown(void)
basic_teardown();
}
+
+/* Test the effects of allocation failures on a straightforward parse */
+START_TEST(test_alloc_parse)
+{
+ const char *text =
+ "<?xml version='1.0' encoding='utf-8'?>\n"
+ "<?pi unknown?>\n"
+ "<doc>Hello, world</doc>";
+ int i;
+ int repeat = 0;
+#define MAX_ALLOC_COUNT 10
+
+ for (i = 0; i < MAX_ALLOC_COUNT; i++) {
+ allocation_count = i;
+ /* Repeat some counts because of cached memory */
+ if (i == 2 && repeat == 2) {
+ i -= 2;
+ repeat++;
+ } else if ((i == 1 && repeat < 2) ||
+ (i == 1 && repeat > 2 && repeat < 5)) {
+ i--;
+ repeat++;
+ }
+ XML_SetProcessingInstructionHandler(parser, dummy_pi_handler);
+ if (_XML_Parse_SINGLE_BYTES(parser, text, strlen(text),
+ XML_TRUE) != XML_STATUS_ERROR)
+ break;
+ XML_ParserReset(parser, NULL);
+ }
+ if (i == 0)
+ fail("Parse succeeded despite failing allocator");
+ if (i == MAX_ALLOC_COUNT)
+ fail("Parse failed with max allocations");
+#undef MAX_ALLOC_COUNT
+}
+END_TEST
+
+
static int XMLCALL
external_entity_duff_loader(XML_Parser parser,
const XML_Char *context,
@@ -4357,6 +4395,7 @@ make_suite(void)
suite_add_tcase(s, tc_alloc);
tcase_add_checked_fixture(tc_alloc, alloc_setup, alloc_teardown);
+ tcase_add_test(tc_alloc, test_alloc_parse);
tcase_add_test(tc_alloc, test_alloc_create_external_parser);
tcase_add_test(tc_alloc, test_alloc_run_external_parser);
tcase_add_test(tc_alloc, test_alloc_dtd_copy_default_atts);
