mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
PSD layer count may be negative
This commit is contained in:
parent
696b82e440
commit
a46f5cdd0a
BIN
Tests/images/negative_layer_count.psd
Normal file
BIN
Tests/images/negative_layer_count.psd
Normal file
Binary file not shown.
|
@ -57,7 +57,8 @@ def test_n_frames():
|
|||
assert im.n_frames == 1
|
||||
assert not im.is_animated
|
||||
|
||||
with Image.open(test_file) as im:
|
||||
for path in [test_file, "Tests/images/negative_layer_count.psd"]:
|
||||
with Image.open(path) as im:
|
||||
assert im.n_frames == 2
|
||||
assert im.is_animated
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ from . import Image, ImageFile, ImagePalette
|
|||
from ._binary import i8
|
||||
from ._binary import i16be as i16
|
||||
from ._binary import i32be as i32
|
||||
from ._binary import si16be as si16
|
||||
|
||||
MODES = {
|
||||
# (photoshop mode, bits) -> (pil mode, required channels)
|
||||
|
@ -179,7 +180,7 @@ def _layerinfo(fp, ct_bytes):
|
|||
def read(size):
|
||||
return ImageFile._safe_read(fp, size)
|
||||
|
||||
ct = i16(read(2))
|
||||
ct = si16(read(2))
|
||||
|
||||
# sanity check
|
||||
if ct_bytes < (abs(ct) * 20):
|
||||
|
|
|
@ -47,6 +47,16 @@ def si16le(c, o=0):
|
|||
return unpack_from("<h", c, o)[0]
|
||||
|
||||
|
||||
def si16be(c, o=0):
|
||||
"""
|
||||
Converts a 2-bytes (16 bits) string to a signed integer, big endian.
|
||||
|
||||
:param c: string containing bytes to convert
|
||||
:param o: offset of bytes to convert in string
|
||||
"""
|
||||
return unpack_from(">h", c, o)[0]
|
||||
|
||||
|
||||
def i32le(c, o=0):
|
||||
"""
|
||||
Converts a 4-bytes (32 bits) string to an unsigned integer.
|
||||
|
|
Loading…
Reference in New Issue
Block a user