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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user