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

core: safe handling of compressed file level extension (.gz[0-9])

- Replace unsafe pointer arithmetic and direct buffer modification with std::string methods.
- Update documentation to clarify that the last digit is used as compression level and truncated from the actual filename.
- Add test cases for .gz and .gz0-9
This commit is contained in:
Kumataro
2026-05-05 07:41:59 +09:00
parent 5cbfe53798
commit 8449b9e468
3 changed files with 42 additions and 13 deletions
+12 -2
View File
@@ -2108,9 +2108,19 @@ T fsWriteRead(const T& expectedValue, const char* ext)
fs_w.release();
FileStorage fs_r(fname, FileStorage::READ);
T value;
fs_r["value"] >> value;
fs_r.release();
// If ext is `.gz[0-9]`, fname on storage will end with `.gz`.
// FileStorage::Impl::open() truncates the last digit internally.
if (isdigit(fname.back()))
{
fname.pop_back();
}
remove(fname.c_str());
return value;
}
@@ -2143,7 +2153,7 @@ TEST_P(FileStorage_exact_type, long_int)
}
INSTANTIATE_TEST_CASE_P(Core_InputOutput,
FileStorage_exact_type, Values(".yml", ".xml", ".json")
FileStorage_exact_type, Values(".yml", ".xml", ".json", ".xml.gz", ".xml.gz0", ".xml.gz9")
);
}} // namespace