From be3c519956296bb9254040a231bd63454d37958c Mon Sep 17 00:00:00 2001 From: Kumataro Date: Fri, 26 Jul 2024 05:55:00 +0900 Subject: [PATCH] core: FileStorage: detect invalid attribute value --- modules/core/src/persistence_xml.cpp | 2 ++ modules/core/test/test_io.cpp | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/modules/core/src/persistence_xml.cpp b/modules/core/src/persistence_xml.cpp index 6141fade2d..ed699758fc 100644 --- a/modules/core/src/persistence_xml.cpp +++ b/modules/core/src/persistence_xml.cpp @@ -737,6 +737,8 @@ public: if( c != '\"' && c != '\'' ) { ptr = skipSpaces( ptr, CV_XML_INSIDE_TAG ); + if(!ptr) + CV_PARSE_ERROR_CPP("Invalid attribute value"); if( *ptr != '\"' && *ptr != '\'' ) CV_PARSE_ERROR_CPP( "Attribute value should be put into single or double quotes" ); } diff --git a/modules/core/test/test_io.cpp b/modules/core/test/test_io.cpp index 16b66e75ee..d7be6e08c6 100644 --- a/modules/core/test/test_io.cpp +++ b/modules/core/test/test_io.cpp @@ -1985,4 +1985,22 @@ INSTANTIATE_TEST_CASE_P( /*nothing*/, Core_InputOutput_regression_25073, Values("test.json", "test.xml", "test.yml") ); +// see https://github.com/opencv/opencv/issues/25946 +TEST(Core_InputOutput, FileStorage_invalid_attribute_value_regression_25946) +{ + const std::string fileName = cv::tempfile("FileStorage_invalid_attribute_value_exception_test.xml"); + const std::string content = "