提交 294f7b62 编写于 作者: J jiangzhiwen

check invalid filename string

上级 a9f4a24e
......@@ -1310,6 +1310,15 @@ ManifestDataset::ManifestDataset(const std::string &dataset_file, const std::str
: dataset_file_(dataset_file), usage_(usage), decode_(decode), class_index_(class_indexing), sampler_(sampler) {}
bool ManifestDataset::ValidateParams() {
std::vector<char> forbidden_symbols = {':', '*', '?', '"', '<', '>', '|', '`', '&', '\'', ';'};
for (char c : dataset_file_) {
auto p = std::find(forbidden_symbols.begin(), forbidden_symbols.end(), c);
if (p != forbidden_symbols.end()) {
MS_LOG(ERROR) << "filename should not contains :*?\"<>|`&;\'";
return false;
}
}
Path manifest_file(dataset_file_);
if (!manifest_file.Exists()) {
MS_LOG(ERROR) << "dataset file: [" << dataset_file_ << "] is invalid or not exist";
......
......@@ -203,6 +203,10 @@ TEST_F(MindDataTestPipeline, TestManifestError) {
// Create a Manifest Dataset with invalid usage
std::shared_ptr<Dataset> ds1 = Manifest(file_path, "invalid_usage");
EXPECT_EQ(ds1, nullptr);
// Create a Manifest Dataset with invalid string
std::shared_ptr<Dataset> ds2 = Manifest(":*?\"<>|`&;'", "train");
EXPECT_EQ(ds2, nullptr);
}
TEST_F(MindDataTestPipeline, TestManifestWithNullSampler) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册