Fix overflow bug when calculation pixel array length

When `width*height` of a rectangle overflows `uint16`, the allocated buffer is too small to hold the actual rectangle.