From f6e792058bde468a436bd9d5da645def2bf0b948 Mon Sep 17 00:00:00 2001 From: shrey kharbanda Date: Wed, 23 Sep 2026 02:10:10 +0000 Subject: [PATCH] test(images): cover malformed JPEG, WebP and PNG headers --- .../images/test_image_edit_utils.py | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/tests/test_litellm/images/test_image_edit_utils.py b/tests/test_litellm/images/test_image_edit_utils.py index fa42ad8e0ea..45b31ee196b 100644 --- a/tests/test_litellm/images/test_image_edit_utils.py +++ b/tests/test_litellm/images/test_image_edit_utils.py @@ -60,6 +60,80 @@ class _NonSeekableStream(io.BytesIO): return False +class _FailingReadStream(io.BytesIO): + def read(self, size: int = -1) -> bytes: + raise OSError("simulated disk read failure") + + +def _jpeg_sof_segment(marker: int, width: int, height: int) -> bytes: + return bytes((0xFF, marker)) + struct.pack(">H", 17) + struct.pack(">BHH", 8, height, width) + + +def _jpeg_segment(marker: int, payload: bytes) -> bytes: + return bytes((0xFF, marker)) + struct.pack(">H", len(payload) + 2) + payload + + +def _webp_chunk(fourcc: bytes, body: bytes) -> bytes: + chunk: Final = fourcc + struct.pack("