mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
Merge pull request #6510 from radarhere/buffer
This commit is contained in:
commit
b607e834a9
BIN
Tests/images/mmap_error.bmp
Normal file
BIN
Tests/images/mmap_error.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.0 KiB |
|
@ -39,6 +39,13 @@ def test_invalid_file():
|
|||
BmpImagePlugin.BmpImageFile(fp)
|
||||
|
||||
|
||||
def test_fallback_if_mmap_errors():
|
||||
# This image has been truncated,
|
||||
# so that the buffer is not large enough when using mmap
|
||||
with Image.open("Tests/images/mmap_error.bmp") as im:
|
||||
assert_image_equal_tofile(im, "Tests/images/pal8_offset.bmp")
|
||||
|
||||
|
||||
def test_save_to_bytes():
|
||||
output = io.BytesIO()
|
||||
im = hopper()
|
||||
|
|
|
@ -192,6 +192,9 @@ class ImageFile(Image.Image):
|
|||
|
||||
with open(self.filename) as fp:
|
||||
self.map = mmap.mmap(fp.fileno(), 0, access=mmap.ACCESS_READ)
|
||||
if offset + self.size[1] * args[1] > self.map.size():
|
||||
# buffer is not large enough
|
||||
raise OSError
|
||||
self.im = Image.core.map_buffer(
|
||||
self.map, self.size, decoder_name, offset, args
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue
Block a user