diff --git a/src/PIL/BmpImagePlugin.py b/src/PIL/BmpImagePlugin.py index 6f730cfef..9947f439b 100644 --- a/src/PIL/BmpImagePlugin.py +++ b/src/PIL/BmpImagePlugin.py @@ -291,7 +291,8 @@ class BmpRleDecoder(ImageFile.PyDecoder): rle4 = self.args[1] data = bytearray() x = 0 - while len(data) < self.state.xsize * self.state.ysize: + dest_length = self.state.xsize * self.state.ysize + while len(data) < dest_length: pixels = self.fd.read(1) byte = self.fd.read(1) if not pixels or not byte: diff --git a/src/PIL/DdsImagePlugin.py b/src/PIL/DdsImagePlugin.py index be17f4223..b89502d1f 100644 --- a/src/PIL/DdsImagePlugin.py +++ b/src/PIL/DdsImagePlugin.py @@ -497,7 +497,8 @@ class DdsRgbDecoder(ImageFile.PyDecoder): data = bytearray() bytecount = bitcount // 8 - while len(data) < self.state.xsize * self.state.ysize * len(masks): + dest_length = self.state.xsize * self.state.ysize * len(masks) + while len(data) < dest_length: value = int.from_bytes(self.fd.read(bytecount), "little") for i, mask in enumerate(masks): masked_value = value & mask diff --git a/src/PIL/PpmImagePlugin.py b/src/PIL/PpmImagePlugin.py index bca3018c3..94bf430b8 100644 --- a/src/PIL/PpmImagePlugin.py +++ b/src/PIL/PpmImagePlugin.py @@ -307,7 +307,8 @@ class PpmDecoder(ImageFile.PyDecoder): out_byte_count = 4 if self.mode == "I" else 1 out_max = 65535 if self.mode == "I" else 255 bands = Image.getmodebands(self.mode) - while len(data) < self.state.xsize * self.state.ysize * bands * out_byte_count: + dest_length = self.state.xsize * self.state.ysize * bands * out_byte_count + while len(data) < dest_length: pixels = self.fd.read(in_byte_count * bands) if len(pixels) < in_byte_count * bands: # eof diff --git a/src/PIL/QoiImagePlugin.py b/src/PIL/QoiImagePlugin.py index a7b9d4a9e..1a2a4d388 100644 --- a/src/PIL/QoiImagePlugin.py +++ b/src/PIL/QoiImagePlugin.py @@ -53,7 +53,8 @@ class QoiDecoder(ImageFile.PyDecoder): data = bytearray() bands = Image.getmodebands(self.mode) - while len(data) < self.state.xsize * self.state.ysize * bands: + dest_length = self.state.xsize * self.state.ysize * bands + while len(data) < dest_length: byte = self.fd.read(1)[0] if byte == 0b11111110: # QOI_OP_RGB value = self.fd.read(3) + self._previous_pixel[3:]