From e65e5bea45e92a118590c69c022d6e6741e3b101 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 10 Jun 2025 20:30:18 +1000 Subject: [PATCH] Start decoding with a zero-initialized array of previously seen pixels --- Tests/images/op_index.qoi | Bin 0 -> 15 bytes Tests/test_file_qoi.py | 6 ++++++ src/PIL/QoiImagePlugin.py | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 Tests/images/op_index.qoi diff --git a/Tests/images/op_index.qoi b/Tests/images/op_index.qoi new file mode 100644 index 0000000000000000000000000000000000000000..e626aafe6a433487cbacb4bdbcbbe5e66e8d07db GIT binary patch literal 15 TcmXTS&rD-rU| None: with pytest.raises(SyntaxError): QoiImagePlugin.QoiImageFile(invalid_file) + + +def test_op_index() -> None: + # QOI_OP_INDEX as the first chunk + with Image.open("Tests/images/op_index.qoi") as im: + assert im.getpixel((0, 0)) == (0, 0, 0, 0) diff --git a/src/PIL/QoiImagePlugin.py b/src/PIL/QoiImagePlugin.py index df552243e..75070abd7 100644 --- a/src/PIL/QoiImagePlugin.py +++ b/src/PIL/QoiImagePlugin.py @@ -51,7 +51,7 @@ class QoiDecoder(ImageFile.PyDecoder): assert self.fd is not None self._previously_seen_pixels = {} - self._add_to_previous_pixels(bytearray((0, 0, 0, 255))) + self._previous_pixel = bytearray((0, 0, 0, 255)) data = bytearray() bands = Image.getmodebands(self.mode)