From 294f7b620a57e2e139cfab06a52c740efbf95cdf Mon Sep 17 00:00:00 2001 From: jiangzhiwen Date: Thu, 3 Sep 2020 22:09:26 +0800 Subject: [PATCH] check invalid filename string --- mindspore/ccsrc/minddata/dataset/api/datasets.cc | 9 +++++++++ tests/ut/cpp/dataset/c_api_dataset_manifest_test.cc | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/mindspore/ccsrc/minddata/dataset/api/datasets.cc b/mindspore/ccsrc/minddata/dataset/api/datasets.cc index 019415bbc71..270057e6dd2 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 5911279d02e..029a6055f6e 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) {