Skip to content

Commit c5e3b7e

Browse files
authored
Merge pull request #96 from FoamyGuy/indexerror_fix
Guard against out of bounds pixel set
2 parents 95b5c09 + 92f5030 commit c5e3b7e

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

adafruit_imageload/png.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ def load( # noqa: PLR0912, PLR0915, Too many branches, Too many statements
113113
for x in range(0, width, pixels_per_byte):
114114
byte = data_bytes[src_b]
115115
for pixel in range(pixels_per_byte):
116-
bmp[x + pixel, y] = (byte >> ((pixels_per_byte - pixel - 1) * depth)) & pixmask
116+
if x + pixel < width:
117+
bmp[x + pixel, y] = (
118+
byte >> ((pixels_per_byte - pixel - 1) * depth)
119+
) & pixmask
117120
src_b += 1
118121
src += scanline + 1
119122
src_b = src

0 commit comments

Comments
 (0)