mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
Merge pull request #4720 from radarhere/accept
Call _accept instead of duplicating code
This commit is contained in:
commit
b667fd83cf
|
@ -263,7 +263,7 @@ class BmpImageFile(ImageFile.ImageFile):
|
|||
# read 14 bytes: magic number, filesize, reserved, header final offset
|
||||
head_data = self.fp.read(14)
|
||||
# choke if the file does not have the required magic bytes
|
||||
if head_data[0:2] != b"BM":
|
||||
if not _accept(head_data):
|
||||
raise SyntaxError("Not a BMP file")
|
||||
# read the start position of the BMP image data (u32)
|
||||
offset = i32(head_data[10:14])
|
||||
|
|
|
@ -46,7 +46,7 @@ class DcxImageFile(PcxImageFile):
|
|||
|
||||
# Header
|
||||
s = self.fp.read(4)
|
||||
if i32(s) != MAGIC:
|
||||
if not _accept(s):
|
||||
raise SyntaxError("not a DCX file")
|
||||
|
||||
# Component directory
|
||||
|
|
|
@ -42,9 +42,8 @@ class FliImageFile(ImageFile.ImageFile):
|
|||
|
||||
# HEAD
|
||||
s = self.fp.read(128)
|
||||
magic = i16(s[4:6])
|
||||
if not (
|
||||
magic in [0xAF11, 0xAF12]
|
||||
_accept(s)
|
||||
and i16(s[14:16]) in [0, 3] # flags
|
||||
and s[20:22] == b"\x00\x00" # reserved
|
||||
):
|
||||
|
@ -60,6 +59,7 @@ class FliImageFile(ImageFile.ImageFile):
|
|||
|
||||
# animation speed
|
||||
duration = i32(s[16:20])
|
||||
magic = i16(s[4:6])
|
||||
if magic == 0xAF11:
|
||||
duration = (duration * 1000) // 70
|
||||
self.info["duration"] = duration
|
||||
|
|
|
@ -63,7 +63,7 @@ class GifImageFile(ImageFile.ImageFile):
|
|||
|
||||
# Screen
|
||||
s = self.fp.read(13)
|
||||
if s[:6] not in [b"GIF87a", b"GIF89a"]:
|
||||
if not _accept(s):
|
||||
raise SyntaxError("not a GIF file")
|
||||
|
||||
self.info["version"] = s[:6]
|
||||
|
|
|
@ -340,7 +340,7 @@ class JpegImageFile(ImageFile.ImageFile):
|
|||
|
||||
s = self.fp.read(3)
|
||||
|
||||
if s != b"\xFF\xD8\xFF":
|
||||
if not _accept(s):
|
||||
raise SyntaxError("not a JPEG file")
|
||||
s = b"\xFF"
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ class MspImageFile(ImageFile.ImageFile):
|
|||
|
||||
# Header
|
||||
s = self.fp.read(32)
|
||||
if s[:4] not in [b"DanM", b"LinS"]:
|
||||
if not _accept(s):
|
||||
raise SyntaxError("not an MSP file")
|
||||
|
||||
# Header checksum
|
||||
|
|
|
@ -43,7 +43,7 @@ class PixarImageFile(ImageFile.ImageFile):
|
|||
|
||||
# assuming a 4-byte magic label
|
||||
s = self.fp.read(4)
|
||||
if s != b"\200\350\000\000":
|
||||
if not _accept(s):
|
||||
raise SyntaxError("not a PIXAR file")
|
||||
|
||||
# read rest of header
|
||||
|
|
|
@ -633,7 +633,7 @@ class PngImageFile(ImageFile.ImageFile):
|
|||
|
||||
def _open(self):
|
||||
|
||||
if self.fp.read(8) != _MAGIC:
|
||||
if not _accept(self.fp.read(8)):
|
||||
raise SyntaxError("not a PNG file")
|
||||
self.__fp = self.fp
|
||||
self.__frame = 0
|
||||
|
|
|
@ -61,7 +61,7 @@ class PsdImageFile(ImageFile.ImageFile):
|
|||
# header
|
||||
|
||||
s = read(26)
|
||||
if s[:4] != b"8BPS" or i16(s[4:]) != 1:
|
||||
if not _accept(s) or i16(s[4:]) != 1:
|
||||
raise SyntaxError("not a PSD file")
|
||||
|
||||
psd_bits = i16(s[22:])
|
||||
|
|
|
@ -58,8 +58,7 @@ class SgiImageFile(ImageFile.ImageFile):
|
|||
headlen = 512
|
||||
s = self.fp.read(headlen)
|
||||
|
||||
# magic number : 474
|
||||
if i16(s) != 474:
|
||||
if not _accept(s):
|
||||
raise ValueError("Not an SGI image file")
|
||||
|
||||
# compression : verbatim or RLE
|
||||
|
|
|
@ -53,7 +53,7 @@ class SunImageFile(ImageFile.ImageFile):
|
|||
|
||||
# HEAD
|
||||
s = self.fp.read(32)
|
||||
if i32(s) != 0x59A66A95:
|
||||
if not _accept(s):
|
||||
raise SyntaxError("not an SUN raster file")
|
||||
|
||||
offset = 32
|
||||
|
|
Loading…
Reference in New Issue
Block a user