Test long attribute value with character ref and a failing allocator

Tests strictly that a character reference at the end of a long default
value for an attribute will trigger the relevant string pool to grow,
and will recover correctly if there is no memory for growth
This commit is contained in:
Rhodri James 2017-03-17 19:29:47 +00:00 committed by Sebastian Pipping
parent 8b5902c886
commit 18106f4d58

View File

@ -7370,6 +7370,60 @@ START_TEST(test_alloc_realloc_long_attribute_value)
#undef MAX_REALLOC_COUNT
END_TEST
/* Test that a character reference at the end of a suitably long
* default value for an attribute can trigger pool growth, and recovers
* if the allocator fails on it.
*/
START_TEST(test_alloc_long_attr_default_with_char_ref)
{
const char *text =
"<!DOCTYPE doc [<!ATTLIST doc a CDATA '"
/* 64 characters per line */
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHI"
"&#x31;'>]>\n"
"<doc/>";
int i;
#define MAX_ALLOC_COUNT 10
int repeat = 0;
for (i = 0; i < MAX_ALLOC_COUNT; i++) {
/* Repeat some counts to defeat cached allocations */
if ((i == 2 && repeat < 3) ||
(i == 3 && repeat == 3) ||
(i == 4 && repeat == 4)) {
i--;
repeat++;
}
allocation_count = i;
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 at maximum allocation count");
}
#undef MAX_ALLOC_COUNT
END_TEST
static void
nsalloc_setup(void)
{
@ -8170,6 +8224,7 @@ make_suite(void)
tcase_add_test(tc_alloc, test_alloc_pi_in_epilog);
tcase_add_test(tc_alloc, test_alloc_comment_in_epilog);
tcase_add_test(tc_alloc, test_alloc_realloc_long_attribute_value);
tcase_add_test(tc_alloc, test_alloc_long_attr_default_with_char_ref);
suite_add_tcase(s, tc_nsalloc);
tcase_add_checked_fixture(tc_nsalloc, nsalloc_setup, nsalloc_teardown);