From 4f65a3e4eedaffa1efcf9ee1eb08f0b504fbc31a Mon Sep 17 00:00:00 2001
From: Chris Reuter <chris@blit.ca>
Date: Mon, 23 Sep 2013 18:03:08 -0400
Subject: [PATCH] Fixed memory overrun bug in gdImageScaleTwoPass

_gdContributionsCalc would compute a window size and then adjust
the left and right positions of the window to make a window within
that size.  However, it was storing the values in the struct *before*
it made the adjustment.  This change fixes that.
---
 src/gd_interpolation.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/gd_interpolation.c b/src/gd_interpolation.c
index 43891e6..71cc150 100644
--- a/src/gd_interpolation.c
+++ b/src/gd_interpolation.c
@@ -953,9 +953,6 @@ static inline LineContribType *_gdContributionsCalc(unsigned int line_size, unsi
 		double dTotalWeight = 0.0;
 		int iSrc;
 
-		res->ContribRow[u].Left = iLeft;
-		res->ContribRow[u].Right = iRight;
-
 		/* Cut edge points to fit in filter window in case of spill-off */
 		if (iRight - iLeft + 1 > windows_size)  {
 			if (iLeft < ((int)src_size - 1 / 2))  {
@@ -965,6 +962,9 @@ static inline LineContribType *_gdContributionsCalc(unsigned int line_size, unsi
 			}
 		}
 
+		res->ContribRow[u].Left = iLeft;
+		res->ContribRow[u].Right = iRight;
+
 		for (iSrc = iLeft; iSrc <= iRight; iSrc++) {
 			dTotalWeight += (res->ContribRow[u].Weights[iSrc-iLeft] =  scale_f_d * (*pFilter)(scale_f_d * (dCenter - (double)iSrc)));
 		}
