Skip to content

Commit

Permalink
Remove use of eval() from recognizer.py (#4480)
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
panzi authored Jan 20, 2025
1 parent 4f9f940 commit 75e1981
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion deepdoc/vision/recognizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from api.utils.file_utils import get_project_base_directory
from .operators import * # noqa: F403
from .operators import preprocess
from . import operators


class Recognizer(object):
Expand Down Expand Up @@ -319,7 +320,7 @@ def preprocess(self, image_list):
]:
new_op_info = op_info.copy()
op_type = new_op_info.pop('type')
preprocess_ops.append(eval(op_type)(**new_op_info))
preprocess_ops.append(getattr(operators, op_type)(**new_op_info))

for im_path in image_list:
im, im_info = preprocess(im_path, preprocess_ops)
Expand Down

0 comments on commit 75e1981

Please sign in to comment.