From 0496f0b1bcca554ea5fcad0e53a672551bd7c101 Mon Sep 17 00:00:00 2001 From: sofijazolotarev Date: Mon, 24 Jun 2024 01:11:50 +0200 Subject: [PATCH] coverage tool done? --- conftest.py | 4 ++++ src/PIL/BlpImagePlugin.py | 6 ++++++ src/PIL/IcnsImagePlugin.py | 7 +++++++ 3 files changed, 17 insertions(+) diff --git a/conftest.py b/conftest.py index 805c67409..1045266ef 100644 --- a/conftest.py +++ b/conftest.py @@ -8,6 +8,8 @@ from PIL import SpiderImagePlugin from PIL import MpegImagePlugin from PIL import ImageCms from PIL import McIdasImagePlugin +from PIL import BlpImagePlugin +from PIL import IcnsImagePlugin pytest_plugins = ["Tests.helper"] @@ -20,6 +22,8 @@ def calculate_coverage(test_name): "branches4": MpegImagePlugin.BitStream.branches, "branches5": ImageCms.ImageCmsProfile.branches, "branches6": McIdasImagePlugin.McIdasImageFile.branches, + "branches7": BlpImagePlugin._BLPBaseDecoder.branches, + "branches8": IcnsImagePlugin.branches, # Add more } diff --git a/src/PIL/BlpImagePlugin.py b/src/PIL/BlpImagePlugin.py index 5c9fba993..e40ea2179 100644 --- a/src/PIL/BlpImagePlugin.py +++ b/src/PIL/BlpImagePlugin.py @@ -40,6 +40,10 @@ from typing import IO from . import Image, ImageFile +branches = { + "1": False, + "2": False, +} class Format(IntEnum): JPEG = 0 @@ -281,9 +285,11 @@ class _BLPBaseDecoder(ImageFile.PyDecoder): def decode(self, buffer: bytes) -> tuple[int, int]: try: + branches["1"] = True; self._read_blp_header() self._load() except struct.error as e: + branches["2"] = True; msg = "Truncated BLP file" raise OSError(msg) from e return -1, 0 diff --git a/src/PIL/IcnsImagePlugin.py b/src/PIL/IcnsImagePlugin.py index 2e7db7040..f90faf397 100644 --- a/src/PIL/IcnsImagePlugin.py +++ b/src/PIL/IcnsImagePlugin.py @@ -33,6 +33,10 @@ if enable_jpeg2k: MAGIC = b"icns" HEADERSIZE = 8 +branches = { + "1": False, + "2": False, +} def nextheader(fobj): return struct.unpack(">4sI", fobj.read(HEADERSIZE)) @@ -44,8 +48,11 @@ def read_32t(fobj, start_length, size): fobj.seek(start) sig = fobj.read(4) if sig != b"\x00\x00\x00\x00": + branches["1"] = True; msg = "Unknown signature, expecting 0x00000000" raise SyntaxError(msg) + else: + branches["2"] = True; return read_32(fobj, (start + 4, length - 4), size)