瀏覽代碼

Remove use of eval() from operators.py (#4888)

Use `np.float32()` instead.

### What problem does this PR solve?

Using `eval()` can lead to code injections.

I think `eval()` is only used to parse a floating point number here.
This change preserves the correct behavior if the string `"None"` is
supplied. But if that behavior isn't intended then this part could be
just deleted instead, since `np.float32()` is parsing strings anyway:

```Python
        if isinstance(scale, str):
            scale = eval(scale)
```

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
tags/v0.17.0
Mathias Panzenböck 8 月之前
父節點
當前提交
6b389e01b5
No account linked to committer's email address
共有 1 個文件被更改,包括 1 次插入1 次删除
  1. 1
    1
      deepdoc/vision/operators.py

+ 1
- 1
deepdoc/vision/operators.py 查看文件

@@ -108,7 +108,7 @@ class NormalizeImage(object):

def __init__(self, scale=None, mean=None, std=None, order='chw', **kwargs):
if isinstance(scale, str):
scale = eval(scale)
scale = np.float32(scale) if scale != 'None' else None
self.scale = np.float32(scale if scale is not None else 1.0 / 255.0)
mean = mean if mean is not None else [0.485, 0.456, 0.406]
std = std if std is not None else [0.229, 0.224, 0.225]

Loading…
取消
儲存