Pillow

Форк
0
/
test_tiff_crashes.py 
54 строки · 2.1 Кб
1
# Reproductions/tests for crashes/read errors in TiffDecode.c
2

3
# When run in Python, all of these images should fail for
4
# one reason or another, either as a buffer overrun,
5
# unrecognized datastream, or truncated image file.
6
# There shouldn't be any segfaults.
7
#
8
# if run like
9
# `valgrind --tool=memcheck pytest test_tiff_crashes.py 2>&1 | grep TiffDecode.c`
10
# the output should be empty. There may be Python issues
11
# in the valgrind especially if run in a debug Python
12
# version.
13
from __future__ import annotations
14

15
import pytest
16

17
from PIL import Image
18

19
from .helper import on_ci
20

21

22
@pytest.mark.parametrize(
23
    "test_file",
24
    [
25
        "Tests/images/crash_1.tif",
26
        "Tests/images/crash_2.tif",
27
        "Tests/images/crash-2020-10-test.tif",
28
        "Tests/images/crash-0c7e0e8e11ce787078f00b5b0ca409a167f070e0.tif",
29
        "Tests/images/crash-0e16d3bfb83be87356d026d66919deaefca44dac.tif",
30
        "Tests/images/crash-1152ec2d1a1a71395b6f2ce6721c38924d025bf3.tif",
31
        "Tests/images/crash-1185209cf7655b5aed8ae5e77784dfdd18ab59e9.tif",
32
        "Tests/images/crash-338516dbd2f0e83caddb8ce256c22db3bd6dc40f.tif",
33
        "Tests/images/crash-4f085cc12ece8cde18758d42608bed6a2a2cfb1c.tif",
34
        "Tests/images/crash-86214e58da443d2b80820cff9677a38a33dcbbca.tif",
35
        "Tests/images/crash-f46f5b2f43c370fe65706c11449f567ecc345e74.tif",
36
        "Tests/images/crash-63b1dffefc8c075ddc606c0a2f5fdc15ece78863.tif",
37
        "Tests/images/crash-74d2a78403a5a59db1fb0a2b8735ac068a75f6e3.tif",
38
        "Tests/images/crash-81154a65438ba5aaeca73fd502fa4850fbde60f8.tif",
39
        "Tests/images/crash-0da013a13571cc8eb457a39fee8db18f8a3c7127.tif",
40
    ],
41
)
42
@pytest.mark.filterwarnings("ignore:Possibly corrupt EXIF data")
43
@pytest.mark.filterwarnings("ignore:Metadata warning")
44
@pytest.mark.filterwarnings("ignore:Truncated File Read")
45
def test_tiff_crashes(test_file: str) -> None:
46
    try:
47
        with Image.open(test_file) as im:
48
            im.load()
49
    except FileNotFoundError:
50
        if on_ci():
51
            raise
52
        pytest.skip("test image not found")
53
    except OSError:
54
        pass
55

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.