Skip to content

Commit 05b55e7

Browse files
committed
Fix pnm test for short files and add X bitmap as recognized type
1 parent d482e8a commit 05b55e7

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Lib/imghdr.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ def test_gif(h, f):
3737

3838
def test_pnm(h, f):
3939
# PBM, PGM, PPM (portable {bit,gray,pix}map; together portable anymap)
40-
if h[0] == 'P' and h[1] in '123456' and h[2] in ' \t\n\r':
40+
if len(h) >= 3 and \
41+
h[0] == 'P' and h[1] in '123456' and h[2] in ' \t\n\r':
4142
return 'pnm'
4243

4344
tests.append(test_pnm)
@@ -56,6 +57,14 @@ def test_rast(h, f):
5657

5758
tests.append(test_rast)
5859

60+
def test_xbm(h, f):
61+
# X bitmap (X10 or X11)
62+
s = '#define '
63+
if h[:len(s)] == s:
64+
return 'xbm'
65+
66+
tests.append(test_xbm)
67+
5968

6069
#--------------------#
6170
# Small test program #

0 commit comments

Comments
 (0)