fix: reject JPEG scans without image data
This commit is contained in:
@@ -99,3 +99,12 @@ def jpeg_without_eoi(data: bytes) -> bytes:
|
||||
"""JPEG без маркера конца: обрезаны последние два байта."""
|
||||
assert data.endswith(b"\xff\xd9")
|
||||
return data[:-2]
|
||||
|
||||
|
||||
def jpeg_with_scan_data(data: bytes, scan_data: bytes = b"") -> bytes:
|
||||
"""Заменяет данные единственного скана, сохраняя заголовки и таблицы."""
|
||||
start = data.index(b"\xff\xda") + 2
|
||||
(length,) = struct.unpack_from(">H", data, start)
|
||||
end = data.index(b"\xff\xd9", start + length)
|
||||
assert b"\xff\xda" not in data[start + length : end]
|
||||
return data[: start + length] + scan_data + data[end:]
|
||||
|
||||
Reference in New Issue
Block a user