mirror of
https://github.com/opencv/opencv.git
synced 2025-06-13 04:52:53 +08:00
core: FileStorage: detect invalid attribute value
This commit is contained in:
parent
5b3f33dd11
commit
be3c519956
@ -737,6 +737,8 @@ public:
|
|||||||
if( c != '\"' && c != '\'' )
|
if( c != '\"' && c != '\'' )
|
||||||
{
|
{
|
||||||
ptr = skipSpaces( ptr, CV_XML_INSIDE_TAG );
|
ptr = skipSpaces( ptr, CV_XML_INSIDE_TAG );
|
||||||
|
if(!ptr)
|
||||||
|
CV_PARSE_ERROR_CPP("Invalid attribute value");
|
||||||
if( *ptr != '\"' && *ptr != '\'' )
|
if( *ptr != '\"' && *ptr != '\'' )
|
||||||
CV_PARSE_ERROR_CPP( "Attribute value should be put into single or double quotes" );
|
CV_PARSE_ERROR_CPP( "Attribute value should be put into single or double quotes" );
|
||||||
}
|
}
|
||||||
|
@ -1985,4 +1985,22 @@ INSTANTIATE_TEST_CASE_P( /*nothing*/,
|
|||||||
Core_InputOutput_regression_25073,
|
Core_InputOutput_regression_25073,
|
||||||
Values("test.json", "test.xml", "test.yml") );
|
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 = "<?xml \n_=";
|
||||||
|
|
||||||
|
std::fstream testFile;
|
||||||
|
testFile.open(fileName.c_str(), std::fstream::out);
|
||||||
|
if(!testFile.is_open()) FAIL();
|
||||||
|
testFile << content;
|
||||||
|
testFile.close();
|
||||||
|
|
||||||
|
FileStorage fs;
|
||||||
|
EXPECT_ANY_THROW( fs.open(fileName, FileStorage::READ + FileStorage::FORMAT_XML) );
|
||||||
|
|
||||||
|
ASSERT_EQ(0, std::remove(fileName.c_str()));
|
||||||
|
}
|
||||||
|
|
||||||
}} // namespace
|
}} // namespace
|
||||||
|
Loading…
Reference in New Issue
Block a user