mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-10-20 10:44:22 +03:00
Do not allow negative offset with memory mapping
This commit is contained in:
parent
8b41e5b479
commit
6d19b8adef
|
@ -164,6 +164,11 @@ class TestImageFile:
|
||||||
with pytest.raises(OSError):
|
with pytest.raises(OSError):
|
||||||
p.close()
|
p.close()
|
||||||
|
|
||||||
|
def test_negative_offset(self) -> None:
|
||||||
|
with Image.open("Tests/images/raw_negative_stride.bin") as im:
|
||||||
|
with pytest.raises(ValueError, match="Tile offset cannot be negative"):
|
||||||
|
im.load()
|
||||||
|
|
||||||
def test_no_format(self) -> None:
|
def test_no_format(self) -> None:
|
||||||
buf = BytesIO(b"\x00" * 255)
|
buf = BytesIO(b"\x00" * 255)
|
||||||
|
|
||||||
|
|
|
@ -313,6 +313,9 @@ class ImageFile(Image.Image):
|
||||||
and args[0] == self.mode
|
and args[0] == self.mode
|
||||||
and args[0] in Image._MAPMODES
|
and args[0] in Image._MAPMODES
|
||||||
):
|
):
|
||||||
|
if offset < 0:
|
||||||
|
msg = "Tile offset cannot be negative"
|
||||||
|
raise ValueError(msg)
|
||||||
try:
|
try:
|
||||||
# use mmap, if possible
|
# use mmap, if possible
|
||||||
import mmap
|
import mmap
|
||||||
|
|
Loading…
Reference in New Issue
Block a user