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

`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.
This commit is contained in:
Mathias Panzenböck 2025-01-20 02:52:30 +01:00 committed by GitHub
parent 938492cbae
commit 4f9f9405b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -19,6 +19,7 @@ from huggingface_hub import snapshot_download
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
@ -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