diff --git a/src/pugixml.cpp b/src/pugixml.cpp index 66493ab92090ac2bb233204d6f53136589803b9f..a0b3241a23604550a73de13741531e538888b88e 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -5825,7 +5825,7 @@ PUGI__NS_BEGIN if (result != ptr && ptr) { // copy old data - assert(new_size > old_size); + assert(new_size >= old_size); memcpy(result, ptr, old_size); // free the previous page if it had no other objects diff --git a/tests/test_xpath.cpp b/tests/test_xpath.cpp index 526854adf005bd02cc96ab57a108f7172b9b5a44..7f74578f4fa1f61790d722adda3b33be39ea2c10 100644 --- a/tests/test_xpath.cpp +++ b/tests/test_xpath.cpp @@ -420,4 +420,18 @@ TEST_XML(xpath_out_of_memory_evaluate_predicate, "<node><a/><a/><a/><a/><a/><a/> #endif } +TEST(xpath_memory_concat_massive) +{ + pugi::xml_document doc; + pugi::xml_node node = doc.append_child(STR("node")); + + for (int i = 0; i < 5000; ++i) + node.append_child(STR("c")).text().set(i % 10); + + pugi::xpath_query q(STR("/")); + size_t size = q.evaluate_string(0, 0, node); + + CHECK(size == 5001); +} + #endif