Skip to content

Commit

Permalink
Merge branch 'escape_codegen' into 'master'
Browse files Browse the repository at this point in the history
Force jinja escape quoted string to prevent security issues when using third party models

See merge request !1220
  • Loading branch information
lu229 committed Nov 5, 2019
2 parents 76004dd + 8cf29eb commit 8a0abca
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion mace/python/tools/operator.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ namespace {{tag}} {
{% for i in range(start, end) %}

void CreateOperator{{i}}(mace::OperatorDef *op) {
MACE_LATENCY_LOGGER(2, "Create operator {{ net.op[i].name }}");
MACE_LATENCY_LOGGER(2, "Create operator",
{{ net.op[i].name|default("undefined")|tojson }});

mace::Argument *arg = nullptr;
op->mutable_arg()->Reserve({{ net.op[i].arg|length }});
Expand Down
4 changes: 2 additions & 2 deletions mace/python/tools/str2vec_maps.cc.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ namespace {{tag}} {
const std::map<std::string, ClProgramInfo> {{variable_name}} = {
{% for key, encrypted_code in maps.items() %}
{
"{{key}}", {
{{key|tojson}}, {
{
{%- for header in encrypted_code['headers'] -%}
"{{header}}",
{{header|tojson}},
{%- endfor -%}
},
{
Expand Down
2 changes: 1 addition & 1 deletion tools/python/template/model.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void CreateTensors(NetDef *net_def) {
namespace {{tag}} {

MACE_API const std::shared_ptr<NetDef> CreateNet() {
MACE_LATENCY_LOGGER(1, "Create net {{ net.name }}");
MACE_LATENCY_LOGGER(1, "Create net ", {{ net.name|default("undefined")|tojson }});

std::shared_ptr<NetDef> net_def(new NetDef());

Expand Down
3 changes: 2 additions & 1 deletion tools/python/template/operator.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ namespace {{tag}} {
{% for i in range(start, end) %}

void CreateOperator{{i}}(mace::OperatorDef *op) {
MACE_LATENCY_LOGGER(2, "Create operator {{ net.op[i].name }}");
MACE_LATENCY_LOGGER(2, "Create operator ",
{{ net.op[i].name|default("undefined")|tojson }});

mace::Argument *arg = nullptr;
op->mutable_arg()->Reserve({{ net.op[i].arg|length }});
Expand Down
3 changes: 2 additions & 1 deletion tools/python/template/tensor_source.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ namespace mace {
namespace {{tag}} {

void CreateTensor{{tensor_id}}(mace::ConstTensor *const_tensor) {
MACE_LATENCY_LOGGER(2, "Create tensor {{ tensor.name }}");
MACE_LATENCY_LOGGER(2, "Create tensor ",
{{ tensor.name|default("undefined")|tojson }});
const_tensor->set_name({{ tensor.name|tojson }});
const_tensor->set_offset({{ tensor.offset }});
const_tensor->set_data_size({{ tensor.data_size }});
Expand Down

0 comments on commit 8a0abca

Please sign in to comment.