From 0418866fb9efc389e99ae406ad380e4b14c304a4 Mon Sep 17 00:00:00 2001 From: hexia Date: Mon, 21 Sep 2020 14:44:28 +0800 Subject: [PATCH] fix codeDex --- .../ccsrc/utils/load_onnx/anf_converter.cc | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/mindspore/ccsrc/utils/load_onnx/anf_converter.cc b/mindspore/ccsrc/utils/load_onnx/anf_converter.cc index b8fb0c8c615..c0e6a13f0f2 100644 --- a/mindspore/ccsrc/utils/load_onnx/anf_converter.cc +++ b/mindspore/ccsrc/utils/load_onnx/anf_converter.cc @@ -58,7 +58,24 @@ int AnfConverter::ValidateFileStr(const std::string &modelFile, std::string file bool AnfConverter::ReadOnnxFromBinary(const std::string &modelFile, google::protobuf::Message *onnx_model) { std::unique_ptr onnx_file(new (std::nothrow) char[PATH_MAX]{0}); - int fd = open(modelFile.c_str(), O_RDONLY); + + if (modelFile.size() > PATH_MAX) { + MS_LOG(DEBUG) << "file path " << modelFile << " is too long."; + return false; + } + char real_path[PATH_MAX + 1] = {0}; +#if defined(_WIN32) || defined(_WIN64) + if (nullptr == _fullpath(real_path, modelFile.c_str(), PATH_MAX)) { + MS_LOG(DEBUG) << modelFile << " does not exit."; + return false; + } +#else + if (nullptr == realpath(modelFile.c_str(), real_path)) { + MS_LOG(DEBUG) << modelFile << " does not exit."; + return false; + } +#endif + int fd = open(real_path, O_RDONLY); if (fd < 0) { MS_LOG(EXCEPTION) << "failed to open file"; }