Skip to content

Commit

Permalink
Remove use of eval() from ocr.py (#4481)
Browse files Browse the repository at this point in the history
`eval(op_name)` -> `getattr(operators, op_name)`

### 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 938492c commit 4f9f940
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion deepdoc/vision/ocr.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from api.utils.file_utils import get_project_base_directory
from .operators import * # noqa: F403
from . import operators
import math
import numpy as np
import cv2
Expand Down Expand Up @@ -55,7 +56,7 @@ def create_operators(op_param_list, global_config=None):
param = {} if operator[op_name] is None else operator[op_name]
if global_config is not None:
param.update(global_config)
op = eval(op_name)(**param)
op = getattr(operators, op_name)(**param)
ops.append(op)
return ops

Expand Down

0 comments on commit 4f9f940

Please sign in to comment.