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