From 7da4a3689353ce4481d186ed6f652fa331c2e50d Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Mon, 11 Apr 2011 08:51:24 -0700 Subject: [PATCH] clamp image bounds in PixelArray::PixelArray() [marcello3d] --- src/PixelArray.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/PixelArray.cc b/src/PixelArray.cc index 2c653f2..007e8f9 100644 --- a/src/PixelArray.cc +++ b/src/PixelArray.cc @@ -98,6 +98,12 @@ PixelArray::PixelArray(Canvas *canvas, int sx, int sy, int width, int height): int srcStride = canvas->stride() , dstStride = stride(); + if (sx < 0) width += sx, sx = 0; + if (sy < 0) height += sy, sy = 0; + if (sx + width > canvas->width) width = canvas->width - sx; + if (sy + height > canvas->height) height = canvas->height - sy; + if (width <= 0 || height <= 0) return; + // Normalize data (argb -> rgba) for (int y = 0; y < height; ++y) { uint32_t *row = (uint32_t *)(src + srcStride * (y + sy));