Skip to content

Commit 347a1d8

Browse files
committed
J2k DOS fix -- CVE-2014-3598
Found and reported by Andrew Drake of dropbox.com
1 parent 3aa9326 commit 347a1d8

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

PIL/Jpeg2KImagePlugin.py

+3
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ def _parse_jp2_header(fp):
7070
else:
7171
hlen = 8
7272

73+
if lbox < hlen:
74+
raise SyntaxError('Invalid JP2 header length')
75+
7376
if tbox == b'jp2h':
7477
header = fp.read(lbox - hlen)
7578
break

Tests/check_j2k_dos.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Tests potential DOS of Jpeg2kImagePlugin with 0 length block.
2+
# Run from anywhere that PIL is importable.
3+
4+
from PIL import Image
5+
from io import BytesIO
6+
7+
if bytes is str:
8+
Image.open(BytesIO(bytes('\x00\x00\x00\x0cjP\x20\x20\x0d\x0a\x87\x0a\x00\x00\x00\x00hang')))
9+
else:
10+
Image.open(BytesIO(bytes('\x00\x00\x00\x0cjP\x20\x20\x0d\x0a\x87\x0a\x00\x00\x00\x00hang', 'latin-1')))
11+

0 commit comments

Comments
 (0)