From d6ea9a9c20f3141e496c32e84a69da49a3d78b0b Mon Sep 17 00:00:00 2001 From: hexia Date: Mon, 21 Sep 2020 21:30:40 +0800 Subject: [PATCH] fix codeDex --- .../ccsrc/utils/load_onnx/anf_converter.cc | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/mindspore/ccsrc/utils/load_onnx/anf_converter.cc b/mindspore/ccsrc/utils/load_onnx/anf_converter.cc index b8fb0c8c61..ef69812bb0 100644 --- a/mindspore/ccsrc/utils/load_onnx/anf_converter.cc +++ b/mindspore/ccsrc/utils/load_onnx/anf_converter.cc @@ -58,7 +58,23 @@ 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"; }