diff --git a/src/robotjs.cc b/src/robotjs.cc index 14e2cb28..93d0d55e 100644 --- a/src/robotjs.cc +++ b/src/robotjs.cc @@ -767,6 +767,12 @@ NAN_METHOD(getColor) //Create the bitmap. bitmap = createMMBitmap(img.image, img.width, img.height, img.byteWidth, img.bitsPerPixel, img.bytesPerPixel); + // Make sure the requested pixel is inside the bitmap. + if (!MMBitmapPointInBounds(bitmap, MMPointMake(x, y))) + { + return Nan::ThrowError("Requested coordinates are outside the bitmap's dimensions."); + } + color = MMRGBHexAtPoint(bitmap, x, y); char hex[7];