From 5820e880db03390fe12639b446f808d0d58ea213 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 23 Nov 2026 22:14:37 +1100 Subject: [PATCH] Use bytearray --- src/PIL/ImImagePlugin.py | 2 +- src/PIL/MpoImagePlugin.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/PIL/ImImagePlugin.py b/src/PIL/ImImagePlugin.py index 4b655e9f373..36ef82d2242 100644 --- a/src/PIL/ImImagePlugin.py +++ b/src/PIL/ImImagePlugin.py @@ -372,7 +372,7 @@ def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None: if im.mode in ["P", "PA"]: im_palette = im.im.getpalette("RGB;L") colors = len(im_palette) // 3 - palette = b"" + palette = bytearray() for i in range(3): palette += im_palette[colors * i : colors * (i + 1)] palette += b"\x00" * (256 - colors) diff --git a/src/PIL/MpoImagePlugin.py b/src/PIL/MpoImagePlugin.py index d34aacc959b..43bf08077f5 100644 --- a/src/PIL/MpoImagePlugin.py +++ b/src/PIL/MpoImagePlugin.py @@ -89,7 +89,7 @@ def _save_all(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None: ifd[0xB000] = b"0100" ifd[0xB001] = len(offsets) - mpentries = b"" + mpentries = bytearray() data_offset = 0 for i, size in enumerate(offsets): if i == 0: @@ -100,7 +100,7 @@ def _save_all(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None: if i == 0: data_offset -= mpf_offset data_offset += size - ifd[0xB002] = mpentries + ifd[0xB002] = bytes(mpentries) fp.seek(mpf_offset) fp.write(b"II\x2a\x00" + o32le(8) + ifd.tobytes(8))