Validation of invalid names in CC factory (#11170)

This commit is contained in:
Vladislav Volkov
2022-03-24 09:47:10 +03:00
committed by GitHub
parent 714d7a79c7
commit 5e6fd8c721
2 changed files with 20 additions and 3 deletions

View File

@@ -3,7 +3,9 @@
//
#pragma once
#include <cctype>
#include <functional>
#include <stdexcept>
#include <string>
#include <type_traits>
#include <unordered_map>
@@ -57,6 +59,7 @@ public:
template <openvino::itt::domain_t (*domain)(), typename Impl>
void registerImpl(const Key& key, const char* typeName) {
validate_type(typeName);
const std::string task_name = "REG$" + name + "$" + to_string(key) + "$" + typeName;
openvino::itt::ScopedTask<domain> task(openvino::itt::handle(task_name));
builders[key] = [](Args... args) -> T {
@@ -109,6 +112,14 @@ public:
}
private:
void validate_type(const char* name) const {
for (const char* ch = name; *ch; ++ch) {
if (!std::isalnum(*ch) && *ch != '_')
throw std::runtime_error(std::string("Invalid identifier name: '") + name +
"'. Allowed characters should be alphanumeric or '_'");
}
}
const std::string& to_string(const std::string& str) const noexcept {
return str;
}

View File

@@ -86,10 +86,13 @@
#include "nodes/priorbox.h"
#include "nodes/priorbox_clustered.h"
namespace ov {
namespace intel_cpu {
#define INTEL_CPU_NODE(__prim, __type) \
registerNodeIfRequired(intel_cpu, __prim, __type, NodeImpl<__prim>)
ov::intel_cpu::Node::NodesFactory::NodesFactory()
Node::NodesFactory::NodesFactory()
: Factory("NodesFactory") {
using namespace node;
INTEL_CPU_NODE(Generic, Type::Generic);
@@ -112,8 +115,8 @@ ov::intel_cpu::Node::NodesFactory::NodesFactory()
INTEL_CPU_NODE(Eltwise, Type::Eltwise);
INTEL_CPU_NODE(SoftMax, Type::Softmax);
INTEL_CPU_NODE(EmbeddingBagPackedSum, Type::EmbeddingBagPackedSum);
INTEL_CPU_NODE(node::Input, Type::Input);
INTEL_CPU_NODE(node::Input, Type::Output);
INTEL_CPU_NODE(Input, Type::Input);
INTEL_CPU_NODE(Input, Type::Output);
INTEL_CPU_NODE(MemoryInput, Type::MemoryInput);
INTEL_CPU_NODE(MemoryOutput, Type::MemoryOutput);
INTEL_CPU_NODE(Tile, Type::Tile);
@@ -182,3 +185,6 @@ ov::intel_cpu::Node::NodesFactory::NodesFactory()
}
#undef INTEL_CPU_NODE
} // namespace intel_cpu
} // namespace ov