diff --git a/ChangeLog b/ChangeLog index ec4028f7f9..00ba136c90 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-07-17 Sven Neumann + + * app/paint-funcs/scale-funcs.c (scale_region_no_resample): use + 64 bit integers to avoid an overflow. Fixes bug #457209. + 2007-07-17 Sven Neumann * app/widgets/gimpcolormapeditor.c: gracefully deal with empty diff --git a/app/paint-funcs/scale-funcs.c b/app/paint-funcs/scale-funcs.c index c4f3f2b305..f1dd29cf24 100644 --- a/app/paint-funcs/scale-funcs.c +++ b/app/paint-funcs/scale-funcs.c @@ -100,18 +100,29 @@ scale_region_no_resample (PixelRegion *srcPR, /* the data pointers... */ x_src_offsets = g_new (gint, width * bytes); y_src_offsets = g_new (gint, height); + src = g_new (guchar, orig_width * bytes); dest = g_new (guchar, width * bytes); /* pre-calc the scale tables */ offset = x_src_offsets; for (x = 0; x < width; x++) - for (b = 0; b < bytes; b++) - *offset++ = b + bytes * ((x * orig_width + orig_width / 2) / width); + { + /* need to use 64 bit integers here to avoid an overflow */ + gint o = ((gint64) x * + (gint64) orig_width + orig_width / 2) / (gint64) width; + + for (b = 0; b < bytes; b++) + *offset++ = o * bytes + b; + } offset = y_src_offsets; for (y = 0; y < height; y++) - *offset++ = (y * orig_height + orig_height / 2) / height; + { + /* need to use 64 bit integers here to avoid an overflow */ + *offset++ = (((gint64) y * (gint64) orig_height + orig_height / 2) / + (gint64) height); + } /* do the scaling */ row_bytes = width * bytes;