forked from mindspore-Ecosystem/mindspore
!5731 Manifest Dataset check invalid filename string
Merge pull request !5731 from jiangzhiwen/fix/invalid_filename_string
This commit is contained in:
commit
d0c7b1ba24
|
@ -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";
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue