Skip to content

Commit

Permalink
restricting usage of built-ins in user's code
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Zhavoronkov committed Dec 14, 2018
1 parent 039d70f commit 0f19d63
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ window.cvat.dashboard.uiCallbacks.push(function(newElements) {
},
error: (data) => {
let message = `Can not get auto annotation meta info. Code: ${data.status}. Message: ${data.responseText || data.statusText}`;
showMessage(message);
throw Error(message);
window.cvat.auto_annotation.badResponse(message);
}
});
});
Expand Down Expand Up @@ -84,10 +83,15 @@ window.cvat.auto_annotation = {
}).fail((data) => {
let message = `Error was occured during check annotation status. ` +
`Code: ${data.status}, text: ${data.responseText || data.statusText}`;
badResponse(message);
window.cvat.auto_annotation.badResponse(message);
});
}
},

badResponse(message) {
showMessage(message);
throw Error(message);
},
};

document.addEventListener("DOMContentLoaded", () => {
Expand Down Expand Up @@ -168,12 +172,9 @@ document.addEventListener("DOMContentLoaded", () => {
}).fail((data) => {
let message = `Error was occured during run annotation request. ` +
`Code: ${data.status}, text: ${data.responseText || data.statusText}`;
badResponse(message);
window.cvat.auto_annotation.badResponse(message);
});

function badResponse(message) {
showMessage(message);
throw Error(message);
}

});
});
26 changes: 19 additions & 7 deletions cvat/apps/auto_annotation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,6 @@ def load_model(model_file, weights_file, config_file):

return model, class_names

def process_detections(detections, path_to_conv_script):
import importlib.util
spec = importlib.util.spec_from_file_location('converter', path_to_conv_script)
converter = importlib.util.module_from_spec(spec)
spec.loader.exec_module(converter)
return converter.process_detections(detections)

def create_anno_container():
return {
"boxes": [],
Expand All @@ -70,6 +63,25 @@ def create_anno_container():
"points_paths": [],
}

def process_detections(detections, path_to_conv_script):
results = create_anno_container()
global_vars = {
'__builtins__': {
'str': str,
'int': int,
'float': float,
'max': max,
'min': min,
'range': range,
},
}
local_vars = {
'detections': detections,
'results': results,
}
exec (open(path_to_conv_script).read(), global_vars, local_vars)
return results

def run_inference_engine_annotation(path_to_data, model_file, weights_file, config_file, convertation_file, job, update_progress, db_labels):
result = {
'create': create_anno_container(),
Expand Down

0 comments on commit 0f19d63

Please sign in to comment.