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

Merge pull request #16488 from vpisarev:filestorage_longlines

trying to fix handling file storages with extremely long lines

* trying to fix handling of file storages with extremely long lines: https://github.com/opencv/opencv/issues/11061

* * fixed errorneous pointer access in JSON parser.
* it's now crash-test time! temporarily set the initial parser buffer size to just 40 bytes. let's run all the test and check if the buffer is always correctly resized and handled

* fixed pointer use in JSON parser; added the proper test to catch this case

* fixed the test to make it more challenging. generate test json with
*
**
***
etc. shape
This commit is contained in:
Vadim Pisarevsky
2020-02-11 18:46:15 +03:00
committed by GitHub
parent aa2777ed61
commit 3efa78311a
3 changed files with 103 additions and 66 deletions
+42
View File
@@ -1669,4 +1669,46 @@ TEST(Core_InputOutput, FileStorage_YAML_parse_multiple_documents)
ASSERT_EQ(0, std::remove(filename.c_str()));
}
TEST(Core_InputOutput, FileStorage_JSON_VeryLongLines)
{
for( int iter = 0; iter < 2; iter++ )
{
std::string temp_path = cv::tempfile("temp.json");
{
std::ofstream ofs(temp_path);
ofs << "{ ";
int prev_len = 0, start = 0;
for (int i = 0; i < 52500; i++)
{
std::string str = cv::format("\"KEY%d\"", i);
ofs << str;
if(iter == 1 && i - start > prev_len)
{
// build a stairway with increasing text row width
ofs << "\n";
prev_len = i - start;
start = i;
}
str = cv::format(": \"VALUE%d\", ", i);
ofs << str;
}
ofs << "}";
}
{
cv::FileStorage fs(temp_path, cv::FileStorage::READ);
char key[16], val0[16];
std::string val;
for(int i = 0; i < 52500; i += 100)
{
sprintf(key, "KEY%d", i);
sprintf(val0, "VALUE%d", i);
fs[key] >> val;
ASSERT_EQ(val, val0);
}
}
remove(temp_path.c_str());
}
}
}} // namespace