Skip to content

Commit

Permalink
test: Don't access out-of-bounds pixels
Browse files Browse the repository at this point in the history
We can only access data_ref and data_now after checking that the
coordinates are in bounds for both.
  • Loading branch information
mvollmer authored and martinpitt committed Jan 24, 2025
1 parent fa91d69 commit 53b9468
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions test/common/testlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1422,28 +1422,30 @@ def img_eq(ref: Image.Image, now: Image.Image, delta: Image.Image) -> bool:
width, height = delta.size
for y in range(height):
for x in range(width):
# we only support RGBA
ref_pixel = data_ref[x, y]
now_pixel = data_now[x, y]
# we only support RGBA, not single-channel float (grayscale)
assert isinstance(ref_pixel, tuple)
assert isinstance(now_pixel, tuple)
if x >= ref.size[0] or x >= now.size[0] or y >= ref.size[1] or y >= now.size[1]:
result = False
elif ref_pixel != now_pixel:
if (
masked(ref_pixel) or
ignorable_coord(x, y) or
ignorable_change(ref_pixel, now_pixel)
):
data_delta[x, y] = (0, 255, 0, 255)
else:
data_delta[x, y] = (255, 0, 0, 255)
count += 1
if count > 20:
result = False
else:
data_delta[x, y] = ref_pixel
# we only support RGBA
ref_pixel = data_ref[x, y]
now_pixel = data_now[x, y]
# we only support RGBA, not single-channel float (grayscale)
assert isinstance(ref_pixel, tuple)
assert isinstance(now_pixel, tuple)

if ref_pixel != now_pixel:
if (
masked(ref_pixel) or
ignorable_coord(x, y) or
ignorable_change(ref_pixel, now_pixel)
):
data_delta[x, y] = (0, 255, 0, 255)
else:
data_delta[x, y] = (255, 0, 0, 255)
count += 1
if count > 20:
result = False
else:
data_delta[x, y] = ref_pixel
return result

if not img_eq(img_ref, img_now, img_delta):
Expand Down

0 comments on commit 53b9468

Please sign in to comment.