Mathias Panzenböck
commited on
Commit
·
1b54e4d
1
Parent(s):
ba2fa9c
Remove use of eval() from recognizer.py (#4480)
Browse files`eval(op_type)` -> `getattr(operators, op_type)`
### What problem does this PR solve?
Using `eval()` can lead to code injections and is entirely unnecessary
here.
### Type of change
- [x] Other (please describe):
Best practice code improvement, preventing the possibility of code
injection.
deepdoc/vision/recognizer.py
CHANGED
@@ -25,6 +25,7 @@ from huggingface_hub import snapshot_download
|
|
25 |
from api.utils.file_utils import get_project_base_directory
|
26 |
from .operators import * # noqa: F403
|
27 |
from .operators import preprocess
|
|
|
28 |
|
29 |
|
30 |
class Recognizer(object):
|
@@ -319,7 +320,7 @@ class Recognizer(object):
|
|
319 |
]:
|
320 |
new_op_info = op_info.copy()
|
321 |
op_type = new_op_info.pop('type')
|
322 |
-
preprocess_ops.append(
|
323 |
|
324 |
for im_path in image_list:
|
325 |
im, im_info = preprocess(im_path, preprocess_ops)
|
|
|
25 |
from api.utils.file_utils import get_project_base_directory
|
26 |
from .operators import * # noqa: F403
|
27 |
from .operators import preprocess
|
28 |
+
from . import operators
|
29 |
|
30 |
|
31 |
class Recognizer(object):
|
|
|
320 |
]:
|
321 |
new_op_info = op_info.copy()
|
322 |
op_type = new_op_info.pop('type')
|
323 |
+
preprocess_ops.append(getattr(operators, op_type)(**new_op_info))
|
324 |
|
325 |
for im_path in image_list:
|
326 |
im, im_info = preprocess(im_path, preprocess_ops)
|