diff options
| author | Trevor Gamblin <trevor.gamblin@windriver.com> | 2022-01-28 13:51:00 -0500 |
|---|---|---|
| committer | Armin Kuster <akuster808@gmail.com> | 2022-01-30 15:13:01 -0800 |
| commit | 23598caeafce0af0dde8d1339cf5edff021f6823 (patch) | |
| tree | 710520a9cae4c2bcd709bd61cc293ea592362852 /meta-python | |
| parent | b5a9b02a9e350beb330339841112b339b8b8c66e (diff) | |
| download | meta-openembedded-23598caeafce0af0dde8d1339cf5edff021f6823.tar.gz | |
python3-pillow: fix CVE-2022-22815, 22816, 22817
Backport three patches from 9.0.0 upstream to fix CVES.
Signed-off-by: Trevor Gamblin <trevor.gamblin@windriver.com>
Signed-off-by: Armin Kuster <akuster808@gmail.com>
Diffstat (limited to 'meta-python')
4 files changed, 185 insertions, 0 deletions
diff --git a/meta-python/recipes-devtools/python/python3-pillow/0001-Handle-case-where-path-count-is-zero.patch b/meta-python/recipes-devtools/python/python3-pillow/0001-Handle-case-where-path-count-is-zero.patch new file mode 100644 index 0000000000..4c4f3d51f5 --- /dev/null +++ b/meta-python/recipes-devtools/python/python3-pillow/0001-Handle-case-where-path-count-is-zero.patch | |||
| @@ -0,0 +1,77 @@ | |||
| 1 | From c48271ab354db49cdbd740bc45e13be4f0f7993c Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Andrew Murray <radarhere@users.noreply.github.com> | ||
| 3 | Date: Mon, 6 Dec 2021 22:25:14 +1100 | ||
| 4 | Subject: [PATCH] Handle case where path count is zero | ||
| 5 | |||
| 6 | CVE: CVE-2022-22816 | ||
| 7 | |||
| 8 | Upstream-Status: Backport | ||
| 9 | (https://github.com/python-pillow/Pillow/pull/5920/commits/c48271ab354db49cdbd740bc45e13be4f0f7993c) | ||
| 10 | |||
| 11 | Signed-off-by: Trevor Gamblin <trevor.gamblin@windriver.com> | ||
| 12 | |||
| 13 | --- | ||
| 14 | Tests/test_imagepath.py | 1 + | ||
| 15 | src/path.c | 33 +++++++++++++++++++-------------- | ||
| 16 | 2 files changed, 20 insertions(+), 14 deletions(-) | ||
| 17 | |||
| 18 | diff --git a/Tests/test_imagepath.py b/Tests/test_imagepath.py | ||
| 19 | index cd850bb1..b18271cc 100644 | ||
| 20 | --- a/Tests/test_imagepath.py | ||
| 21 | +++ b/Tests/test_imagepath.py | ||
| 22 | @@ -90,6 +90,7 @@ def test_path_odd_number_of_coordinates(): | ||
| 23 | [ | ||
| 24 | ([0, 1, 2, 3], (0.0, 1.0, 2.0, 3.0)), | ||
| 25 | ([3, 2, 1, 0], (1.0, 0.0, 3.0, 2.0)), | ||
| 26 | + (0, (0.0, 0.0, 0.0, 0.0)), | ||
| 27 | (1, (0.0, 0.0, 0.0, 0.0)), | ||
| 28 | ], | ||
| 29 | ) | ||
| 30 | diff --git a/src/path.c b/src/path.c | ||
| 31 | index 64c767cb..dea274ee 100644 | ||
| 32 | --- a/src/path.c | ||
| 33 | +++ b/src/path.c | ||
| 34 | @@ -327,21 +327,26 @@ path_getbbox(PyPathObject *self, PyObject *args) { | ||
| 35 | |||
| 36 | xy = self->xy; | ||
| 37 | |||
| 38 | - x0 = x1 = xy[0]; | ||
| 39 | - y0 = y1 = xy[1]; | ||
| 40 | + if (self->count == 0) { | ||
| 41 | + x0 = x1 = 0; | ||
| 42 | + y0 = y1 = 0; | ||
| 43 | + } else { | ||
| 44 | + x0 = x1 = xy[0]; | ||
| 45 | + y0 = y1 = xy[1]; | ||
| 46 | |||
| 47 | - for (i = 1; i < self->count; i++) { | ||
| 48 | - if (xy[i + i] < x0) { | ||
| 49 | - x0 = xy[i + i]; | ||
| 50 | - } | ||
| 51 | - if (xy[i + i] > x1) { | ||
| 52 | - x1 = xy[i + i]; | ||
| 53 | - } | ||
| 54 | - if (xy[i + i + 1] < y0) { | ||
| 55 | - y0 = xy[i + i + 1]; | ||
| 56 | - } | ||
| 57 | - if (xy[i + i + 1] > y1) { | ||
| 58 | - y1 = xy[i + i + 1]; | ||
| 59 | + for (i = 1; i < self->count; i++) { | ||
| 60 | + if (xy[i + i] < x0) { | ||
| 61 | + x0 = xy[i + i]; | ||
| 62 | + } | ||
| 63 | + if (xy[i + i] > x1) { | ||
| 64 | + x1 = xy[i + i]; | ||
| 65 | + } | ||
| 66 | + if (xy[i + i + 1] < y0) { | ||
| 67 | + y0 = xy[i + i + 1]; | ||
| 68 | + } | ||
| 69 | + if (xy[i + i + 1] > y1) { | ||
| 70 | + y1 = xy[i + i + 1]; | ||
| 71 | + } | ||
| 72 | } | ||
| 73 | } | ||
| 74 | |||
| 75 | -- | ||
| 76 | 2.33.0 | ||
| 77 | |||
diff --git a/meta-python/recipes-devtools/python/python3-pillow/0001-Initialize-coordinates-to-zero.patch b/meta-python/recipes-devtools/python/python3-pillow/0001-Initialize-coordinates-to-zero.patch new file mode 100644 index 0000000000..758531f678 --- /dev/null +++ b/meta-python/recipes-devtools/python/python3-pillow/0001-Initialize-coordinates-to-zero.patch | |||
| @@ -0,0 +1,45 @@ | |||
| 1 | From 1e092419b6806495c683043ab3feb6ce264f3b9c Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Andrew Murray <radarhere@users.noreply.github.com> | ||
| 3 | Date: Mon, 6 Dec 2021 22:24:19 +1100 | ||
| 4 | Subject: [PATCH] Initialize coordinates to zero | ||
| 5 | |||
| 6 | CVE: CVE-2022-22815 | ||
| 7 | |||
| 8 | Upstream-Status: Backport | ||
| 9 | (https://github.com/python-pillow/Pillow/pull/5920/commits/1e092419b6806495c683043ab3feb6ce264f3b9c) | ||
| 10 | |||
| 11 | Signed-off-by: Trevor Gamblin <trevor.gamblin@windriver.com> | ||
| 12 | |||
| 13 | --- | ||
| 14 | Tests/test_imagepath.py | 1 + | ||
| 15 | src/path.c | 2 +- | ||
| 16 | 2 files changed, 2 insertions(+), 1 deletion(-) | ||
| 17 | |||
| 18 | diff --git a/Tests/test_imagepath.py b/Tests/test_imagepath.py | ||
| 19 | index 0835fdb4..cd850bb1 100644 | ||
| 20 | --- a/Tests/test_imagepath.py | ||
| 21 | +++ b/Tests/test_imagepath.py | ||
| 22 | @@ -90,6 +90,7 @@ def test_path_odd_number_of_coordinates(): | ||
| 23 | [ | ||
| 24 | ([0, 1, 2, 3], (0.0, 1.0, 2.0, 3.0)), | ||
| 25 | ([3, 2, 1, 0], (1.0, 0.0, 3.0, 2.0)), | ||
| 26 | + (1, (0.0, 0.0, 0.0, 0.0)), | ||
| 27 | ], | ||
| 28 | ) | ||
| 29 | def test_getbbox(coords, expected): | ||
| 30 | diff --git a/src/path.c b/src/path.c | ||
| 31 | index 4764c58a..64c767cb 100644 | ||
| 32 | --- a/src/path.c | ||
| 33 | +++ b/src/path.c | ||
| 34 | @@ -57,7 +57,7 @@ alloc_array(Py_ssize_t count) { | ||
| 35 | if ((unsigned long long)count > (SIZE_MAX / (2 * sizeof(double))) - 1) { | ||
| 36 | return ImagingError_MemoryError(); | ||
| 37 | } | ||
| 38 | - xy = malloc(2 * count * sizeof(double) + 1); | ||
| 39 | + xy = calloc(2 * count * sizeof(double) + 1, sizeof(double)); | ||
| 40 | if (!xy) { | ||
| 41 | ImagingError_MemoryError(); | ||
| 42 | } | ||
| 43 | -- | ||
| 44 | 2.33.0 | ||
| 45 | |||
diff --git a/meta-python/recipes-devtools/python/python3-pillow/0001-Restrict-builtins-for-ImageMath.eval.patch b/meta-python/recipes-devtools/python/python3-pillow/0001-Restrict-builtins-for-ImageMath.eval.patch new file mode 100644 index 0000000000..4c266cc418 --- /dev/null +++ b/meta-python/recipes-devtools/python/python3-pillow/0001-Restrict-builtins-for-ImageMath.eval.patch | |||
| @@ -0,0 +1,60 @@ | |||
| 1 | From 8531b01d6cdf0b70f256f93092caa2a5d91afc11 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Andrew Murray <radarhere@users.noreply.github.com> | ||
| 3 | Date: Sun, 2 Jan 2022 17:23:49 +1100 | ||
| 4 | Subject: [PATCH] Restrict builtins for ImageMath.eval | ||
| 5 | |||
| 6 | CVE: CVE-2022-22817 | ||
| 7 | |||
| 8 | Upstream-Status: Backport | ||
| 9 | (https://github.com/python-pillow/Pillow/pull/5923/commits/8531b01d6cdf0b70f256f93092caa2a5d91afc11) | ||
| 10 | |||
| 11 | Signed-off-by: Trevor Gamblin <trevor.gamblin@windriver.com> | ||
| 12 | |||
| 13 | --- | ||
| 14 | Tests/test_imagemath.py | 7 +++++++ | ||
| 15 | src/PIL/ImageMath.py | 7 ++++++- | ||
| 16 | 2 files changed, 13 insertions(+), 1 deletion(-) | ||
| 17 | |||
| 18 | diff --git a/Tests/test_imagemath.py b/Tests/test_imagemath.py | ||
| 19 | index e7afd1ab..25811aa8 100644 | ||
| 20 | --- a/Tests/test_imagemath.py | ||
| 21 | +++ b/Tests/test_imagemath.py | ||
| 22 | @@ -1,3 +1,5 @@ | ||
| 23 | +import pytest | ||
| 24 | + | ||
| 25 | from PIL import Image, ImageMath | ||
| 26 | |||
| 27 | |||
| 28 | @@ -50,6 +52,11 @@ def test_ops(): | ||
| 29 | assert pixel(ImageMath.eval("float(B)**33", images)) == "F 8589934592.0" | ||
| 30 | |||
| 31 | |||
| 32 | +def test_prevent_exec(): | ||
| 33 | + with pytest.raises(ValueError): | ||
| 34 | + ImageMath.eval("exec('pass')") | ||
| 35 | + | ||
| 36 | + | ||
| 37 | def test_logical(): | ||
| 38 | assert pixel(ImageMath.eval("not A", images)) == 0 | ||
| 39 | assert pixel(ImageMath.eval("A and B", images)) == "L 2" | ||
| 40 | diff --git a/src/PIL/ImageMath.py b/src/PIL/ImageMath.py | ||
| 41 | index 7f9c88e1..06bea800 100644 | ||
| 42 | --- a/src/PIL/ImageMath.py | ||
| 43 | +++ b/src/PIL/ImageMath.py | ||
| 44 | @@ -246,7 +246,12 @@ def eval(expression, _dict={}, **kw): | ||
| 45 | if hasattr(v, "im"): | ||
| 46 | args[k] = _Operand(v) | ||
| 47 | |||
| 48 | - out = builtins.eval(expression, args) | ||
| 49 | + code = compile(expression, "<string>", "eval") | ||
| 50 | + for name in code.co_names: | ||
| 51 | + if name not in args and name != "abs": | ||
| 52 | + raise ValueError(f"'{name}' not allowed") | ||
| 53 | + | ||
| 54 | + out = builtins.eval(expression, {"__builtins": {"abs": abs}}, args) | ||
| 55 | try: | ||
| 56 | return out.im | ||
| 57 | except AttributeError: | ||
| 58 | -- | ||
| 59 | 2.33.0 | ||
| 60 | |||
diff --git a/meta-python/recipes-devtools/python/python3-pillow_8.2.0.bb b/meta-python/recipes-devtools/python/python3-pillow_8.2.0.bb index 8279544a8f..4393d9356d 100644 --- a/meta-python/recipes-devtools/python/python3-pillow_8.2.0.bb +++ b/meta-python/recipes-devtools/python/python3-pillow_8.2.0.bb | |||
| @@ -11,6 +11,9 @@ SRC_URI = "git://github.com/python-pillow/Pillow.git;branch=8.2.x;protocol=https | |||
| 11 | file://0001-Limit-sprintf-modes-to-10-characters.patch \ | 11 | file://0001-Limit-sprintf-modes-to-10-characters.patch \ |
| 12 | file://0001-Use-snprintf-instead-of-sprintf.patch \ | 12 | file://0001-Use-snprintf-instead-of-sprintf.patch \ |
| 13 | file://0001-Raise-ValueError-if-color-specifier-is-too-long.patch \ | 13 | file://0001-Raise-ValueError-if-color-specifier-is-too-long.patch \ |
| 14 | file://0001-Initialize-coordinates-to-zero.patch \ | ||
| 15 | file://0001-Handle-case-where-path-count-is-zero.patch \ | ||
| 16 | file://0001-Restrict-builtins-for-ImageMath.eval.patch \ | ||
| 14 | " | 17 | " |
| 15 | SRCREV ?= "e0e353c0ef7516979a9aedce3792596649ce4433" | 18 | SRCREV ?= "e0e353c0ef7516979a9aedce3792596649ce4433" |
| 16 | 19 | ||
