diff --git a/mindspore/ccsrc/minddata/dataset/api/datasets.cc b/mindspore/ccsrc/minddata/dataset/api/datasets.cc index 019415bbc7198944cfa9ae22cf836a0d19cd2880..270057e6dd27dc8cfe2c425cb95325df5f362ef1 100644 --- a/mindspore/ccsrc/minddata/dataset/api/datasets.cc +++ b/mindspore/ccsrc/minddata/dataset/api/datasets.cc @@ -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 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"; diff --git a/tests/ut/cpp/dataset/c_api_dataset_manifest_test.cc b/tests/ut/cpp/dataset/c_api_dataset_manifest_test.cc index 5911279d02e402c0975b3aaf0c407eb949461d1e..029a6055f6e2556e6d26beff6a270eb9bf97ef70 100644 --- a/tests/ut/cpp/dataset/c_api_dataset_manifest_test.cc +++ b/tests/ut/cpp/dataset/c_api_dataset_manifest_test.cc @@ -203,6 +203,10 @@ TEST_F(MindDataTestPipeline, TestManifestError) { // Create a Manifest Dataset with invalid usage std::shared_ptr ds1 = Manifest(file_path, "invalid_usage"); EXPECT_EQ(ds1, nullptr); + + // Create a Manifest Dataset with invalid string + std::shared_ptr ds2 = Manifest(":*?\"<>|`&;'", "train"); + EXPECT_EQ(ds2, nullptr); } TEST_F(MindDataTestPipeline, TestManifestWithNullSampler) {