Skip to content

Commit 3a87f93

Browse files
committed
- Security Issue python#2: imageop did not validate arguments correctly and could
segfault as a result. CVE-2008-4864. backport r66689
1 parent b7cfda1 commit 3a87f93

File tree

3 files changed

+175
-168
lines changed

3 files changed

+175
-168
lines changed

Lib/test/test_imageop.py

+63-8
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,70 @@
55
Roger E. Masse
66
"""
77

8-
from test.test_support import verbose, unlink
8+
from test.test_support import verbose, unlink, run_unittest
9+
10+
import imageop, uu, os, unittest
11+
12+
SIZES = (1, 2, 3, 4)
13+
_VALUES = (1, 2, 2**10, 2**15-1, 2**15, 2**15+1, 2**31-2, 2**31-1)
14+
VALUES = tuple( -x for x in reversed(_VALUES) ) + (0,) + _VALUES
15+
AAAAA = "A" * 1024
16+
17+
18+
class InputValidationTests(unittest.TestCase):
19+
20+
def _check(self, name, size=None, *extra):
21+
func = getattr(imageop, name)
22+
for height in VALUES:
23+
for width in VALUES:
24+
strlen = abs(width * height)
25+
if size:
26+
strlen *= size
27+
if strlen < 1024:
28+
data = "A" * strlen
29+
else:
30+
data = AAAAA
31+
if size:
32+
arguments = (data, size, width, height) + extra
33+
else:
34+
arguments = (data, width, height) + extra
35+
try:
36+
func(*arguments)
37+
except (ValueError, imageop.error):
38+
pass
39+
40+
def check_size(self, name, *extra):
41+
for size in SIZES:
42+
self._check(name, size, *extra)
43+
44+
def check(self, name, *extra):
45+
self._check(name, None, *extra)
46+
47+
def test_input_validation(self):
48+
self.check_size("crop", 0, 0, 0, 0)
49+
self.check_size("scale", 1, 0)
50+
self.check_size("scale", -1, -1)
51+
self.check_size("tovideo")
52+
self.check("grey2mono", 128)
53+
self.check("grey2grey4")
54+
self.check("grey2grey2")
55+
self.check("dither2mono")
56+
self.check("dither2grey2")
57+
self.check("mono2grey", 0, 0)
58+
self.check("grey22grey")
59+
self.check("rgb2rgb8") # nlen*4 == len
60+
self.check("rgb82rgb")
61+
self.check("rgb2grey")
62+
self.check("grey2rgb")
63+
64+
65+
def test_main(use_rgbimg=True):
66+
run_unittest(InputValidationTests)
967

10-
import imageop, uu, os
11-
12-
def main(use_rgbimg=1):
68+
try:
69+
import imgfile
70+
except ImportError:
71+
return
1372

1473
# Create binary test files
1574
uu.decode(get_qualified_path('testrgb'+os.extsep+'uue'), 'test'+os.extsep+'rgb')
@@ -165,7 +224,3 @@ def get_qualified_path(name):
165224
if os.path.exists(fullname):
166225
return fullname
167226
return name
168-
169-
# rgbimg (unlike imgfile) is portable to platforms other than SGI.
170-
# So we prefer to use it.
171-
main(use_rgbimg=1)

Misc/NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ Core and builtins
3535
less than zero will now raise a SystemError and return NULL to indicate a
3636
bug in the calling C code. CVE-2008-1887.
3737

38+
- Security Issue #2: imageop did not validate arguments correctly and could
39+
segfault as a result. CVE-2008-4864.
40+
3841
Extension Modules
3942
-----------------
4043

0 commit comments

Comments
 (0)