diff --git a/expat/tests/runtests.c b/expat/tests/runtests.c
index 16f305ff..0b861a74 100644
--- a/expat/tests/runtests.c
+++ b/expat/tests/runtests.c
@@ -5887,29 +5887,7 @@ external_entity_public(XML_Parser parser,
const XML_Char *systemId,
const XML_Char *publicId)
{
- const char *text1 =
- "\n"
- "\n"
- "\n"
- "%e1;\n";
+ const char *text1 = (const char *)XML_GetUserData(parser);
const char *text2 = "";
const char *text;
XML_Parser ext_parser;
@@ -5935,6 +5913,29 @@ START_TEST(test_alloc_public_entity_value)
const char *text =
"\n"
"\n";
+ char dtd_text[] =
+ "\n"
+ "\n"
+ "\n"
+ "%e1;\n";
int i;
#define MAX_ALLOC_COUNT 25
int repeat = 0;
@@ -5952,6 +5953,7 @@ START_TEST(test_alloc_public_entity_value)
}
allocation_count = i;
dummy_handler_flags = 0;
+ XML_SetUserData(parser, dtd_text);
XML_SetParamEntityParsing(parser, XML_PARAM_ENTITY_PARSING_ALWAYS);
XML_SetExternalEntityRefHandler(parser, external_entity_public);
/* Provoke a particular code path */
@@ -5971,6 +5973,69 @@ START_TEST(test_alloc_public_entity_value)
#undef MAX_ALLOC_COUNT
END_TEST
+START_TEST(test_alloc_realloc_subst_public_entity_value)
+{
+ const char *text =
+ "\n"
+ "\n";
+ char dtd_text[] =
+ "\n"
+ "\n"
+ "%ThisIsAStupidlyLongParameterNameIntendedToTriggerPoolGrowth12345"
+ "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
+ "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
+ "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
+ "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
+ "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
+ "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
+ "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
+ "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
+ "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
+ "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
+ "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
+ "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
+ "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
+ "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
+ "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP;";
+ int i;
+#define MAX_REALLOC_COUNT 10
+
+ for (i = 0; i < MAX_REALLOC_COUNT; i++) {
+ reallocation_count = i;
+ XML_SetUserData(parser, dtd_text);
+ XML_SetParamEntityParsing(parser, XML_PARAM_ENTITY_PARSING_ALWAYS);
+ XML_SetExternalEntityRefHandler(parser, external_entity_public);
+ if (_XML_Parse_SINGLE_BYTES(parser, text, strlen(text),
+ XML_TRUE) != XML_STATUS_ERROR)
+ break;
+ XML_ParserReset(parser, NULL);
+ }
+ if (i == 0)
+ fail("Parsing worked despite failing reallocation");
+ if (i == MAX_REALLOC_COUNT)
+ fail("Parsing failed at max reallocation count");
+}
+#undef MAX_REALLOC_COUNT
+END_TEST
+
START_TEST(test_alloc_parse_public_doctype)
{
const char *text =
@@ -7342,6 +7407,7 @@ make_suite(void)
tcase_add_test(tc_alloc, test_alloc_ext_entity_realloc_buffer);
tcase_add_test(tc_alloc, test_alloc_realloc_many_attributes);
tcase_add_test(tc_alloc, test_alloc_public_entity_value);
+ tcase_add_test(tc_alloc, test_alloc_realloc_subst_public_entity_value);
tcase_add_test(tc_alloc, test_alloc_parse_public_doctype);
tcase_add_test(tc_alloc, test_alloc_parse_public_doctype_long_name);
tcase_add_test(tc_alloc, test_alloc_set_foreign_dtd);