Mathias Panzenböck commited on
Commit
ba2fa9c
·
1 Parent(s): f620d16

Remove use of eval() from ocr.py (#4481)

Browse files

`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.

Files changed (1) hide show
  1. deepdoc/vision/ocr.py +2 -1
deepdoc/vision/ocr.py CHANGED
@@ -19,6 +19,7 @@ from huggingface_hub import snapshot_download
19
 
20
  from api.utils.file_utils import get_project_base_directory
21
  from .operators import * # noqa: F403
 
22
  import math
23
  import numpy as np
24
  import cv2
@@ -55,7 +56,7 @@ def create_operators(op_param_list, global_config=None):
55
  param = {} if operator[op_name] is None else operator[op_name]
56
  if global_config is not None:
57
  param.update(global_config)
58
- op = eval(op_name)(**param)
59
  ops.append(op)
60
  return ops
61
 
 
19
 
20
  from api.utils.file_utils import get_project_base_directory
21
  from .operators import * # noqa: F403
22
+ from . import operators
23
  import math
24
  import numpy as np
25
  import cv2
 
56
  param = {} if operator[op_name] is None else operator[op_name]
57
  if global_config is not None:
58
  param.update(global_config)
59
+ op = getattr(operators, op_name)(**param)
60
  ops.append(op)
61
  return ops
62