Fixed _binary handling in _accept methods

This commit is contained in:
Andrew Murray 2015-06-18 10:12:12 +10:00
parent 1f9f9cc206
commit 4c02ae4061
6 changed files with 6 additions and 6 deletions

View File

@ -33,7 +33,7 @@ i32 = _binary.i32le
def _accept(prefix):
return i32(prefix) == MAGIC
return len(prefix) >= 4 and i32(prefix) == MAGIC
##

View File

@ -187,7 +187,7 @@ class PSFile(object):
def _accept(prefix):
return prefix[:4] == b"%!PS" or i32(prefix) == 0xC6D3D0C5
return prefix[:4] == b"%!PS" or (len(prefix) >= 4 and i32(prefix) == 0xC6D3D0C5)
##
# Image plugin for Encapsulated Postscript. This plugin supports only

View File

@ -30,7 +30,7 @@ o8 = _binary.o8
# decoder
def _accept(prefix):
return i16(prefix[4:6]) in [0xAF11, 0xAF12]
return len(prefix) >= 6 and i16(prefix[4:6]) in [0xAF11, 0xAF12]
##

View File

@ -19,7 +19,7 @@ i32 = _binary.i32be
def _accept(prefix):
return i32(prefix) >= 20 and i32(prefix[4:8]) == 1
return len(prefix) >= 8 and i32(prefix) >= 20 and i32(prefix[4:8]) == 1
##

View File

@ -29,7 +29,7 @@ i32 = _binary.i32be
def _accept(prefix):
return i16(prefix) == 474
return len(prefix) >= 2 and i16(prefix) == 474
##

View File

@ -27,7 +27,7 @@ i32 = _binary.i32be
def _accept(prefix):
return i32(prefix) == 0x59a66a95
return len(prefix) >= 4 and i32(prefix) == 0x59a66a95
##