From a232e8ae44b00e063482d600f6a01b492c9a95b9 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 24 Jan 2026 11:15:26 +1100 Subject: [PATCH] Stop reading when the end of the file is reached --- src/PIL/DdsImagePlugin.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/PIL/DdsImagePlugin.py b/src/PIL/DdsImagePlugin.py index 312f602a6..063df1974 100644 --- a/src/PIL/DdsImagePlugin.py +++ b/src/PIL/DdsImagePlugin.py @@ -509,7 +509,10 @@ class DdsRgbDecoder(ImageFile.PyDecoder): bytecount = bitcount // 8 dest_length = self.state.xsize * self.state.ysize * len(masks) while len(data) < dest_length: - value = int.from_bytes(self.fd.read(bytecount), "little") + bytes_read = self.fd.read(bytecount) + if len(bytes_read) < bytecount: + break + value = int.from_bytes(bytes_read, "little") for i, mask in enumerate(masks): masked_value = value & mask # Remove the zero padding, and scale it to 8 bits