mirror of
git://git.openembedded.org/meta-openembedded
synced 2026-01-01 13:58:06 +00:00
python3-pillow: Fix for CVE-2023-50447
Upstream-Status: Backport [45c726fd4d&0ca3c33c59&557ba59d13] Signed-off-by: Vijay Anusuri <vanusuri@mvista.com> Signed-off-by: Armin Kuster <akuster808@gmail.com>
This commit is contained in:
parent
3c1bd6e007
commit
c74ebbddfd
|
|
@ -0,0 +1,31 @@
|
|||
From 45c726fd4daa63236a8f3653530f297dc87b160a Mon Sep 17 00:00:00 2001
|
||||
From: Eric Soroos <eric-github@soroos.net>
|
||||
Date: Fri, 27 Oct 2023 11:21:18 +0200
|
||||
Subject: [PATCH] Don't allow __ or builtins in env dictionarys for
|
||||
ImageMath.eval
|
||||
|
||||
Upstream-Status: Backport [https://github.com/python-pillow/Pillow/commit/45c726fd4daa63236a8f3653530f297dc87b160a]
|
||||
CVE: CVE-2023-50447
|
||||
Signed-off-by: Vijay Anusuri <vanusuri@mvista.com>
|
||||
---
|
||||
src/PIL/ImageMath.py | 4 ++++
|
||||
1 file changed, 4 insertions(+)
|
||||
|
||||
diff --git a/src/PIL/ImageMath.py b/src/PIL/ImageMath.py
|
||||
index 392151c10..4cea3855e 100644
|
||||
--- a/src/PIL/ImageMath.py
|
||||
+++ b/src/PIL/ImageMath.py
|
||||
@@ -261,6 +261,10 @@ def eval(expression, _dict={}, **kw):
|
||||
args.update(_dict)
|
||||
args.update(kw)
|
||||
for k, v in list(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)
|
||||
|
||||
--
|
||||
2.25.1
|
||||
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
From 0ca3c33c59927e1c7e0c14dbc1eea1dfb2431a80 Mon Sep 17 00:00:00 2001
|
||||
From: Andrew Murray <radarhere@users.noreply.github.com>
|
||||
Date: Sat, 28 Oct 2023 15:58:52 +1100
|
||||
Subject: [PATCH] Allow ops
|
||||
|
||||
Upstream-Status: Backport [https://github.com/python-pillow/Pillow/commit/0ca3c33c59927e1c7e0c14dbc1eea1dfb2431a80]
|
||||
CVE: CVE-2023-50447
|
||||
Signed-off-by: Vijay Anusuri <vanusuri@mvista.com>
|
||||
---
|
||||
Tests/test_imagemath.py | 4 ++++
|
||||
src/PIL/ImageMath.py | 9 +++++----
|
||||
2 files changed, 9 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/Tests/test_imagemath.py b/Tests/test_imagemath.py
|
||||
index da41b3a12..14a58a532 100644
|
||||
--- a/Tests/test_imagemath.py
|
||||
+++ b/Tests/test_imagemath.py
|
||||
@@ -56,6 +56,10 @@ class TestImageMath(PillowTestCase):
|
||||
pixel(ImageMath.eval("float(B)**33", images)), "F 8589934592.0"
|
||||
)
|
||||
|
||||
+ def test_prevent_double_underscores():
|
||||
+ with pytest.raises(ValueError):
|
||||
+ ImageMath.eval("1", {"__": None})
|
||||
+
|
||||
def test_logical(self):
|
||||
self.assertEqual(pixel(ImageMath.eval("not A", images)), 0)
|
||||
self.assertEqual(pixel(ImageMath.eval("A and B", images)), "L 2")
|
||||
diff --git a/src/PIL/ImageMath.py b/src/PIL/ImageMath.py
|
||||
index 4cea3855e..776604e3f 100644
|
||||
--- a/src/PIL/ImageMath.py
|
||||
+++ b/src/PIL/ImageMath.py
|
||||
@@ -258,13 +258,14 @@ def eval(expression, _dict={}, **kw):
|
||||
|
||||
# build execution namespace
|
||||
args = ops.copy()
|
||||
- args.update(_dict)
|
||||
- args.update(kw)
|
||||
- for k, v in list(args.items()):
|
||||
- if '__' in k or hasattr(__builtins__, k):
|
||||
+ for k in list(_dict.keys()) + list(kw.keys()):
|
||||
+ if "__" in k or hasattr(__builtins__, k):
|
||||
msg = f"'{k}' not allowed"
|
||||
raise ValueError(msg)
|
||||
|
||||
+ args.update(_dict)
|
||||
+ args.update(kw)
|
||||
+ for k, v in list(args.items()):
|
||||
if hasattr(v, "im"):
|
||||
args[k] = _Operand(v)
|
||||
|
||||
--
|
||||
2.25.1
|
||||
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
From 557ba59d13de919d04b3fd4cdef8634f7d4b3348 Mon Sep 17 00:00:00 2001
|
||||
From: Andrew Murray <radarhere@users.noreply.github.com>
|
||||
Date: Sat, 30 Dec 2023 09:30:12 +1100
|
||||
Subject: [PATCH] Include further builtins
|
||||
|
||||
Upstream-Status: Backport [https://github.com/python-pillow/Pillow/commit/557ba59d13de919d04b3fd4cdef8634f7d4b3348]
|
||||
CVE: CVE-2023-50447
|
||||
Signed-off-by: Vijay Anusuri <vanusuri@mvista.com>
|
||||
---
|
||||
Tests/test_imagemath.py | 4 ++++
|
||||
src/PIL/ImageMath.py | 2 +-
|
||||
2 files changed, 5 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/Tests/test_imagemath.py b/Tests/test_imagemath.py
|
||||
index 14a58a532..5bba832e2 100644
|
||||
--- a/Tests/test_imagemath.py
|
||||
+++ b/Tests/test_imagemath.py
|
||||
@@ -60,6 +60,10 @@ class TestImageMath(PillowTestCase):
|
||||
with pytest.raises(ValueError):
|
||||
ImageMath.eval("1", {"__": None})
|
||||
|
||||
+ def test_prevent_builtins():
|
||||
+ with pytest.raises(ValueError):
|
||||
+ ImageMath.eval("(lambda: exec('exit()'))()", {"exec": None})
|
||||
+
|
||||
def test_logical(self):
|
||||
self.assertEqual(pixel(ImageMath.eval("not A", images)), 0)
|
||||
self.assertEqual(pixel(ImageMath.eval("A and B", images)), "L 2")
|
||||
diff --git a/src/PIL/ImageMath.py b/src/PIL/ImageMath.py
|
||||
index 776604e3f..c6bc22180 100644
|
||||
--- a/src/PIL/ImageMath.py
|
||||
+++ b/src/PIL/ImageMath.py
|
||||
@@ -259,7 +259,7 @@ def eval(expression, _dict={}, **kw):
|
||||
# build execution namespace
|
||||
args = ops.copy()
|
||||
for k in list(_dict.keys()) + list(kw.keys()):
|
||||
- if "__" in k or hasattr(__builtins__, k):
|
||||
+ if "__" in k or hasattr(builtins, k):
|
||||
msg = f"'{k}' not allowed"
|
||||
raise ValueError(msg)
|
||||
|
||||
--
|
||||
2.25.1
|
||||
|
||||
|
|
@ -9,6 +9,9 @@ SRC_URI = "git://github.com/python-pillow/Pillow.git;branch=6.2.x;protocol=https
|
|||
file://0001-support-cross-compiling.patch \
|
||||
file://0001-explicitly-set-compile-options.patch \
|
||||
file://0001-CVE-2022-45198.patch \
|
||||
file://CVE-2023-50447-1.patch \
|
||||
file://CVE-2023-50447-2.patch \
|
||||
file://CVE-2023-50447-3.patch \
|
||||
"
|
||||
SRCREV ?= "6e0f07bbe38def22d36ee176b2efd9ea74b453a6"
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user