diff --git a/src/cpp/rtps/xmlparser/XMLDynamicParser.cpp b/src/cpp/rtps/xmlparser/XMLDynamicParser.cpp index eb5533c5f9c..59498ed75b4 100644 --- a/src/cpp/rtps/xmlparser/XMLDynamicParser.cpp +++ b/src/cpp/rtps/xmlparser/XMLDynamicParser.cpp @@ -1001,7 +1001,15 @@ p_dynamictypebuilder_t XMLParser::parseXMLMemberDynamicType( uint32_t length = types::MAX_ELEMENTS_COUNT; if (lengthStr != nullptr) { - length = static_cast(std::stoi(lengthStr)); + try + { + length = static_cast(std::stoi(lengthStr)); + } + catch (const std::exception&) + { + logError(XMLPARSER, "Error parsing member sequence length in line " << p_root->GetLineNum()); + return nullptr; + } } if (!isArray) @@ -1077,7 +1085,15 @@ p_dynamictypebuilder_t XMLParser::parseXMLMemberDynamicType( uint32_t length = types::MAX_ELEMENTS_COUNT; if (lengthStr != nullptr) { - length = static_cast(std::stoi(lengthStr)); + try + { + length = static_cast(std::stoi(lengthStr)); + } + catch (const std::exception&) + { + logError(XMLPARSER, "Error parsing map member sequence length in line " << p_root->GetLineNum()) + return nullptr; + } } if (!isArray) diff --git a/test/unittest/xmlparser/XMLParserTests.cpp b/test/unittest/xmlparser/XMLParserTests.cpp index 58abdfd6c40..01856b4468a 100644 --- a/test/unittest/xmlparser/XMLParserTests.cpp +++ b/test/unittest/xmlparser/XMLParserTests.cpp @@ -56,6 +56,7 @@ TEST_F(XMLParserTests, regressions) EXPECT_EQ(XMLP_ret::XML_ERROR, XMLParser::loadXML("regressions/12736.xml", root)); EXPECT_EQ(XMLP_ret::XML_ERROR, XMLParser::loadXML("regressions/13418.xml", root)); + EXPECT_EQ(XMLP_ret::XML_ERROR, XMLParser::loadXML("regressions/13454.xml", root)); EXPECT_EQ(XMLP_ret::XML_ERROR, XMLParser::loadXML("regressions/13513.xml", root)); EXPECT_EQ(XMLP_ret::XML_ERROR, XMLParser::loadXML("regressions/14456.xml", root)); EXPECT_EQ(XMLP_ret::XML_ERROR, XMLParser::loadXML("regressions/15344.xml", root)); diff --git a/test/unittest/xmlparser/regressions/13454.xml b/test/unittest/xmlparser/regressions/13454.xml new file mode 100644 index 00000000000..6f628328523 --- /dev/null +++ b/test/unittest/xmlparser/regressions/13454.xml @@ -0,0 +1,2 @@ +�8dd~pJeo7�!> +