From c2db67b9dafd6de629e637fb30512d3adb58325f Mon Sep 17 00:00:00 2001 From: Hirundo Date: Sat, 11 Feb 2012 23:32:13 +0100 Subject: [PATCH] Fix #3666: Properly catch out-of-bounds image reads (based on patch by Rubidium) --- nml/output_grf.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nml/output_grf.py b/nml/output_grf.py index 9cd5f80a..e939d14a 100644 --- a/nml/output_grf.py +++ b/nml/output_grf.py @@ -119,6 +119,9 @@ def print_sprite(self, sprite_info): y = sprite_info.ypos.value size_x = sprite_info.xsize.value size_y = sprite_info.ysize.value + (im_width, im_height) = im.size + if x + size_x > im_width or y + size_y > im_height: + raise generic.ScriptError("Read beyond bounds of image file '%s'" % sprite_info.file.value, sprite_info.file.pos) sprite = im.crop((x, y, x + size_x, y + size_y)) # Check for white pixels; those that cause "artefacts" when shading