!5731 Manifest Dataset check invalid filename string

Merge pull request !5731 from jiangzhiwen/fix/invalid_filename_string
This commit is contained in:
mindspore-ci-bot 2020-09-04 16:36:29 +08:00 committed by Gitee
commit d0c7b1ba24
2 changed files with 13 additions and 0 deletions

View File

@ -1311,6 +1311,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";

View File

@ -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) {