ultralytics 8.3.234 Security fix: ast.literal_eval for safer evaluation of metadata strings (#22847)
Signed-off-by: Onuralp SEZER <onuralp@ultralytics.com> Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com> Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
parent
b91e2884fb
commit
265b92fa08
@ -1,6 +1,6 @@
|
||||
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
|
||||
|
||||
__version__ = "8.3.233"
|
||||
__version__ = "8.3.234"
|
||||
|
||||
import importlib
|
||||
import os
|
||||
|
||||
@ -606,7 +606,7 @@ class AutoBackend(nn.Module):
|
||||
if k in {"stride", "batch", "channels"}:
|
||||
metadata[k] = int(v)
|
||||
elif k in {"imgsz", "names", "kpt_shape", "kpt_names", "args"} and isinstance(v, str):
|
||||
metadata[k] = eval(v)
|
||||
metadata[k] = ast.literal_eval(v)
|
||||
stride = metadata["stride"]
|
||||
task = metadata["task"]
|
||||
batch = metadata["batch"]
|
||||
|
||||
@ -1730,10 +1730,10 @@ def guess_model_task(model):
|
||||
if isinstance(model, torch.nn.Module): # PyTorch model
|
||||
for x in "model.args", "model.model.args", "model.model.model.args":
|
||||
with contextlib.suppress(Exception):
|
||||
return eval(x)["task"]
|
||||
return eval(x)["task"] # nosec B307: safe eval of known attribute paths
|
||||
for x in "model.yaml", "model.model.yaml", "model.model.model.yaml":
|
||||
with contextlib.suppress(Exception):
|
||||
return cfg2task(eval(x))
|
||||
return cfg2task(eval(x)) # nosec B307: safe eval of known attribute paths
|
||||
for m in model.modules():
|
||||
if isinstance(m, (Segment, YOLOESegment)):
|
||||
return "segment"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user