Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions checks/check_imaging_leaks.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#!/usr/bin/env python3
from __future__ import annotations

import sys
from collections.abc import Callable
from typing import Any

import pytest

from PIL import Image

from .helper import is_win32

min_iterations = 100
max_iterations = 10000

pytestmark = pytest.mark.skipif(is_win32(), reason="requires Unix or macOS")
pytestmark = pytest.mark.skipif(
sys.platform.startswith("win32"), reason="requires Unix or macOS"
)


def _get_mem_usage() -> float:
Expand Down
11 changes: 6 additions & 5 deletions checks/check_j2k_leaks.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from __future__ import annotations

import sys
from io import BytesIO

import pytest

from PIL import Image

from .helper import is_win32, skip_unless_feature
from PIL import Image, features

# Limits for testing the leak
mem_limit = 1024 * 1048576
Expand All @@ -15,8 +14,10 @@
test_file = "Tests/images/rgb_trns_ycbc.jp2"

pytestmark = [
pytest.mark.skipif(is_win32(), reason="requires Unix or macOS"),
skip_unless_feature("jpg_2000"),
pytest.mark.skipif(
sys.platform.startswith("win32"), reason="requires Unix or macOS"
),
pytest.mark.skipif(not features.check("jpg_2000"), reason="jpg_2000 not available"),
]


Expand Down
32 changes: 17 additions & 15 deletions checks/check_jpeg_leaks.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from __future__ import annotations

import sys
from io import BytesIO

import pytest

from .helper import hopper, is_win32
from PIL import Image

iterations = 5000

Expand All @@ -18,7 +19,9 @@
"""


pytestmark = pytest.mark.skipif(is_win32(), reason="requires Unix or macOS")
pytestmark = pytest.mark.skipif(
sys.platform.startswith("win32"), reason="requires Unix or macOS"
)

"""
pre patch:
Expand Down Expand Up @@ -112,10 +115,10 @@
),
)
def test_qtables_leak(qtables: tuple[tuple[int, ...]] | list[tuple[int, ...]]) -> None:
im = hopper("RGB")
for _ in range(iterations):
test_output = BytesIO()
im.save(test_output, "JPEG", qtables=qtables)
with Image.open("Tests/images/hopper.ppm") as im:
for _ in range(iterations):
test_output = BytesIO()
im.save(test_output, "JPEG", qtables=qtables)


def test_exif_leak() -> None:
Expand Down Expand Up @@ -173,12 +176,12 @@ def test_exif_leak() -> None:
0 +----------------------------------------------------------------------->Gi
0 11.33
"""
im = hopper("RGB")
exif = b"12345678" * 4096

for _ in range(iterations):
test_output = BytesIO()
im.save(test_output, "JPEG", exif=exif)
with Image.open("Tests/images/hopper.ppm") as im:
for _ in range(iterations):
test_output = BytesIO()
im.save(test_output, "JPEG", exif=exif)


def test_base_save() -> None:
Expand Down Expand Up @@ -207,8 +210,7 @@ def test_base_save() -> None:
| :@ @@ @ # : : :: :: @:: :::: :::: :::: : : : : : : :::::::::::: :::@:::
0 +----------------------------------------------------------------------->Gi
0 7.882"""
im = hopper("RGB")

for _ in range(iterations):
test_output = BytesIO()
im.save(test_output, "JPEG")
with Image.open("Tests/images/hopper.ppm") as im:
for _ in range(iterations):
test_output = BytesIO()
im.save(test_output, "JPEG")
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ skip_install = true
deps =
-r .ci/requirements-mypy.txt
commands =
mypy conftest.py selftest.py setup.py docs src winbuild Tests {posargs}
mypy conftest.py selftest.py setup.py checks docs src winbuild Tests {posargs}
Loading