|
|
|
@ -51,14 +51,15 @@ namespace {
|
|
|
|
|
* If such an exception is encountered during operation,
|
|
|
|
|
* the proto file can be divided into several small files or the limit value can be increased.
|
|
|
|
|
*/
|
|
|
|
|
const int kFileSizeOutLimitedOrOpenFailed = -1;
|
|
|
|
|
const int kProtoReadBytesLimit = INT_MAX; // Max size of 2 GB minus 1 byte.
|
|
|
|
|
const int kWarningThreshold = 536870912 * 2; // 536870912 represent 512M
|
|
|
|
|
const int kWarningThreshold = 1073741824; // 536870912 * 2 536870912 represent 512M
|
|
|
|
|
|
|
|
|
|
/// The maximum length of the file.
|
|
|
|
|
const uint32_t kMaxFileSizeLimit = UINT32_MAX; // 4G for now
|
|
|
|
|
const int kMaxBuffSize = 256;
|
|
|
|
|
const char *const kPathValidReason = "The path can only contain 'a-z' 'A-Z' '0-9' '-' '.' '_' and chinese character";
|
|
|
|
|
constexpr uint32_t kMaxConfigFileByte = 10 * 1024 * 1024;
|
|
|
|
|
constexpr uint32_t kMaxConfigFileByte = 10485760; // 10 * 1024 * 1024
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
namespace ge {
|
|
|
|
@ -76,7 +77,8 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool ReadProtoFromBinaryFile(co
|
|
|
|
|
std::string real_path = RealPath(file);
|
|
|
|
|
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(real_path.empty(), return false, "pb file path '%s' not valid", file);
|
|
|
|
|
|
|
|
|
|
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(GetFileLength(real_path) == -1, return false, "file size not valid.");
|
|
|
|
|
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(GetFileLength(real_path) == kFileSizeOutLimitedOrOpenFailed, return false,
|
|
|
|
|
"file size not valid.");
|
|
|
|
|
|
|
|
|
|
std::ifstream fs(real_path, std::ifstream::in | std::ifstream::binary);
|
|
|
|
|
if (!fs.is_open()) {
|
|
|
|
@ -120,17 +122,17 @@ long GetFileLength(const std::string &input_file) {
|
|
|
|
|
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(
|
|
|
|
|
mmGetFileSize(input_file.c_str(), &file_length) != EN_OK,
|
|
|
|
|
ErrorManager::GetInstance().ATCReportErrMessage("E19001", {"file", "errmsg"}, {input_file, strerror(errno)});
|
|
|
|
|
return -1, "Open file[%s] failed. %s", input_file.c_str(), strerror(errno));
|
|
|
|
|
return kFileSizeOutLimitedOrOpenFailed, "Open file[%s] failed. %s", input_file.c_str(), strerror(errno));
|
|
|
|
|
|
|
|
|
|
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG((file_length == 0),
|
|
|
|
|
ErrorManager::GetInstance().ATCReportErrMessage("E19015", {"filepath"}, {input_file});
|
|
|
|
|
return -1, "File[%s] size is 0, not valid.", input_file.c_str());
|
|
|
|
|
|
|
|
|
|
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(file_length > kMaxFileSizeLimit,
|
|
|
|
|
ErrorManager::GetInstance().ATCReportErrMessage(
|
|
|
|
|
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(
|
|
|
|
|
file_length > kMaxFileSizeLimit, ErrorManager::GetInstance().ATCReportErrMessage(
|
|
|
|
|
"E19016", {"filepath", "filesize", "maxlen"},
|
|
|
|
|
{input_file, std::to_string(file_length), std::to_string(kMaxFileSizeLimit)});
|
|
|
|
|
return -1, "File[%s] size %lld is out of limit: %d.", input_file.c_str(), file_length,
|
|
|
|
|
return kFileSizeOutLimitedOrOpenFailed, "File[%s] size %lld is out of limit: %d.", input_file.c_str(), file_length,
|
|
|
|
|
kMaxFileSizeLimit);
|
|
|
|
|
return static_cast<long>(file_length);
|
|
|
|
|
}
|
|
|
|
@ -210,8 +212,8 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY int CreateDirectory(const std::
|
|
|
|
|
GE_CHK_BOOL_EXEC(!directory_path.empty(), return -1, "directory path is empty.");
|
|
|
|
|
auto dir_path_len = directory_path.length();
|
|
|
|
|
if (dir_path_len >= MMPA_MAX_PATH) {
|
|
|
|
|
ErrorManager::GetInstance().ATCReportErrMessage(
|
|
|
|
|
"E19002", {"filepath", "size"}, {directory_path, std::to_string(MMPA_MAX_PATH)});
|
|
|
|
|
ErrorManager::GetInstance().ATCReportErrMessage("E19002", {"filepath", "size"},
|
|
|
|
|
{directory_path, std::to_string(MMPA_MAX_PATH)});
|
|
|
|
|
GELOGW("Path[%s] len is too long, it must be less than %d", directory_path.c_str(), MMPA_MAX_PATH);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
@ -224,8 +226,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY int CreateDirectory(const std::
|
|
|
|
|
if (ret != 0) {
|
|
|
|
|
if (errno != EEXIST) {
|
|
|
|
|
ErrorManager::GetInstance().ATCReportErrMessage("E19006", {"path"}, {directory_path});
|
|
|
|
|
GELOGW("Can not create directory %s. Make sure the directory exists and writable.",
|
|
|
|
|
directory_path.c_str());
|
|
|
|
|
GELOGW("Can not create directory %s. Make sure the directory exists and writable.", directory_path.c_str());
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -350,7 +351,8 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool CheckInt64MulOverflow(int6
|
|
|
|
|
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY std::string RealPath(const char *path) {
|
|
|
|
|
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(path == nullptr, return "", "path pointer is NULL.");
|
|
|
|
|
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(strlen(path) >= MMPA_MAX_PATH,
|
|
|
|
|
ErrorManager::GetInstance().ATCReportErrMessage("E19002", {"filepath", "size"}, {path, std::to_string(MMPA_MAX_PATH)});
|
|
|
|
|
ErrorManager::GetInstance().ATCReportErrMessage("E19002", {"filepath", "size"},
|
|
|
|
|
{path, std::to_string(MMPA_MAX_PATH)});
|
|
|
|
|
return "", "Path[%s] len is too long, it must be less than %d", path, MMPA_MAX_PATH);
|
|
|
|
|
|
|
|
|
|
// Nullptr is returned when the path does not exist or there is no permission
|
|
|
|
@ -418,7 +420,8 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool CheckOutputPathValid(const
|
|
|
|
|
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(strlen(file_path.c_str()) >= MMPA_MAX_PATH,
|
|
|
|
|
ErrorManager::GetInstance().ATCReportErrMessage(
|
|
|
|
|
"E19002", {"filepath", "size"}, {file_path, std::to_string(MMPA_MAX_PATH)});
|
|
|
|
|
return "", "Path[%s] len is too long, it must be less than %d", file_path.c_str(), MMPA_MAX_PATH);
|
|
|
|
|
return "", "Path[%s] len is too long, it must be less than %d", file_path.c_str(),
|
|
|
|
|
MMPA_MAX_PATH);
|
|
|
|
|
|
|
|
|
|
// A regular matching expression to verify the validity of the input file path
|
|
|
|
|
// Path section: Support upper and lower case letters, numbers dots(.) chinese and underscores
|
|
|
|
|