getBmpFromPixels() crashes ofImage.resize() [with suggested bugfix]

getBmpFromPixels() crashed repeatedly when I tried to rescale grayscale Images of size 3026*2048.

It’s because memcpy overshoots the src pixel array because dstStride can be larger than srcStride.

In ofImage.cpp

getBmpFromPixels()

around line 119, I believe, it should read:

  
  
...  
	int srcStride = width * pix.getBytesPerPixel();  
	int dstStride = FreeImage_GetPitch(bmp);  
	unsigned char* src = (unsigned char*) pixels;  
	unsigned char* dst = bmpBits;  
	for(int i = 0; i < (int)height; i++) {  
		// memcpy(dst, src, dstStride);  
		memcpy(dst, src, srcStride);	 	// did overshoot with e.g. grayscale img of size 3026*2048  
		src += srcStride;  
		dst += dstStride;  
	}  
...  
  

thanks for this - I’ll post it as an issue to github
https://github.com/openframeworks/openFrameworks/issues/698

Cheers! =)