From 45c726fd4daa63236a8f3653530f297dc87b160a Mon Sep 17 00:00:00 2001 From: Eric Soroos Date: Fri, 27 Oct 2023 11:21:18 +0200 Subject: [PATCH] Don't allow __ or builtins in env dictionarys for ImageMath.eval --- src/PIL/ImageMath.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/PIL/ImageMath.py b/src/PIL/ImageMath.py index 7ca512e75..cf108e258 100644 --- a/src/PIL/ImageMath.py +++ b/src/PIL/ImageMath.py @@ -237,6 +237,10 @@ def eval(expression, _dict={}, **kw): args.update(_dict) args.update(kw) for k, v in args.items(): + if '__' in k or hasattr(__builtins__, k): + msg = f"'{k}' not allowed" + raise ValueError(msg) + if hasattr(v, "im"): args[k] = _Operand(v)