1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 07:43:03 +04:00

core(persistence): fix "use after free" bug

- do not store user-controlled "FileStorage" pointer
- store FileStorage::Impl pointer instead
This commit is contained in:
Alexander Alekhin
2020-07-17 21:39:06 +00:00
parent a199d7adf1
commit ffe0d50447
3 changed files with 52 additions and 19 deletions
+23
View File
@@ -1788,4 +1788,27 @@ TEST(Core_InputOutput, FileStorage_copy_constructor_17412)
EXPECT_EQ(0, remove(fname.c_str()));
}
TEST(Core_InputOutput, FileStorage_copy_constructor_17412_heap)
{
std::string fname = tempfile("test.yml");
FileStorage fs_orig(fname, cv::FileStorage::WRITE);
fs_orig << "string" << "wat";
fs_orig.release();
// no crash anymore
cv::FileStorage fs;
// use heap to allow valgrind detections
{
cv::FileStorage* fs2 = new cv::FileStorage(fname, cv::FileStorage::READ);
fs = *fs2;
delete fs2;
}
std::string s;
fs["string"] >> s;
EXPECT_EQ(s, "wat");
EXPECT_EQ(0, remove(fname.c_str()));
}
}} // namespace