From 20aef1cd4b436a8859a54b41cc992db517c61d2d Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Thu, 10 Sep 2020 09:11:46 -0700 Subject: [PATCH] Fix stack overflow in tests on MSVC x64 The default stack on MSVC/x64/debug is sufficient for 1692 nested invocations only, whereas on clang/linux it's ~8K... For now set the limit to be conservative. --- src/pugiconfig.hpp | 3 +++ src/pugixml.cpp | 2 +- tests/test_xpath_parse.cpp | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/pugiconfig.hpp b/src/pugiconfig.hpp index 2fb6918..c9c40e2 100644 --- a/src/pugiconfig.hpp +++ b/src/pugiconfig.hpp @@ -40,6 +40,9 @@ // #define PUGIXML_MEMORY_OUTPUT_STACK 10240 // #define PUGIXML_MEMORY_XPATH_PAGE_SIZE 4096 +// Tune this constant to adjust max nesting for XPath queries +// #define PUGIXML_XPATH_DEPTH_LIMIT 1024 + // Uncomment this to switch to header-only version // #define PUGIXML_HEADER_ONLY diff --git a/src/pugixml.cpp b/src/pugixml.cpp index 34e126f..e166458 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -11147,7 +11147,7 @@ PUGI__NS_BEGIN #ifdef PUGIXML_XPATH_DEPTH_LIMIT PUGIXML_XPATH_DEPTH_LIMIT #else - 4096 + 1024 #endif ; diff --git a/tests/test_xpath_parse.cpp b/tests/test_xpath_parse.cpp index 89c66a3..d0b0bac 100644 --- a/tests/test_xpath_parse.cpp +++ b/tests/test_xpath_parse.cpp @@ -394,7 +394,7 @@ static std::basic_string rep(const std::basic_string& base, size TEST(xpath_parse_depth_limit) { - const size_t limit = 5000; + const size_t limit = 1500; CHECK_XPATH_FAIL((rep(STR("("), limit) + STR("1") + rep(STR(")"), limit)).c_str()); CHECK_XPATH_FAIL((STR("(id('a'))") + rep(STR("[1]"), limit)).c_str());