File commit_1f8b1b034ccf1713a5d123a4c327290f86d17d53.diff of Package kdelibs4
commit 1f8b1b034ccf1713a5d123a4c327290f86d17d53
Author: Maks Orlovich <maksim@kde.org>
Date: Mon Feb 6 07:11:08 2012 -0500
Fix sign extension causing image scaling to read from wrong locations
with very high ratios.
diff --git a/khtml/imload/scaledimageplane.h b/khtml/imload/scaledimageplane.h
--- a/khtml/imload/scaledimageplane.h
+++ b/khtml/imload/scaledimageplane.h
@@ -19,16 +19,18 @@
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef SCALED_IMAGE_PLANE_H
#define SCALED_IMAGE_PLANE_H
+#include <cassert>
+
#include "array2d.h"
#include "imageplane.h"
#include "rawimageplane.h"
#include "imagetile.h"
namespace khtmlImLoad {
/**
@@ -43,31 +45,35 @@ private:
unsigned int* calcScaleTable(unsigned int orig, unsigned int scaled)
{
if (scaled == 0)
return 0; // Don't need to compute origin for 0 pixels..
//### I bet this has all sorts of imprecision problems w/high ratios
unsigned int* origin = new unsigned int[scaled];
-
+
//### FIXME: replace with something that clamps on right edge later?
double ratio = double(orig)/double(scaled);
- int intRatio = int(ratio*65536.0 + 1);
- int pos = 0;
-
+
+ // Should be assured by ImageManager::isAcceptableScaleSize
+ assert(ratio < 65536);
+
+ unsigned intRatio = unsigned(ratio*65536.0 + 1);
+ unsigned pos = 0;
+
for (unsigned int pix = 0; pix < scaled; pix++)
{
origin[pix] = pos >> 16;
pos += intRatio;
}
-
+
return origin;
}
-
+
unsigned int* xScaleTable;
unsigned int* yScaleTable;
public:
virtual ~ScaledImagePlane();
virtual void flushCache();
ScaledImagePlane(unsigned int _width, unsigned int _height, RawImagePlane* _parent):