check invalid filename string

This commit is contained in:
jiangzhiwen 2020-09-03 22:09:26 +08:00
parent a9f4a24e2a
commit 294f7b620a
2 changed files with 13 additions and 0 deletions

View File

@ -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";

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