Skip to content

Commit d65576b

Browse files
committed
Throw catchable error if requested pixels are outside the bitmap's dimensions.
1 parent 3eef8cb commit d65576b

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/robotjs.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,12 @@ NAN_METHOD(getColor)
767767
//Create the bitmap.
768768
bitmap = createMMBitmap(img.image, img.width, img.height, img.byteWidth, img.bitsPerPixel, img.bytesPerPixel);
769769

770+
// Make sure the requested pixel is inside the bitmap.
771+
if (!MMBitmapPointInBounds(bitmap, MMPointMake(x, y)))
772+
{
773+
return Nan::ThrowError("Requested coordinates are outside the bitmap's dimensions.");
774+
}
775+
770776
color = MMRGBHexAtPoint(bitmap, x, y);
771777

772778
char hex[7];

0 commit comments

Comments
 (0)