Bug in MagickEvaluateImages

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Bug in MagickEvaluateImages

Post by el_supremo »

I'm using IM 6.9.7-10 on Windows 10 Pro x64 and ran into a problem with MagickEvaluateImages in which it was crashing with a simple test program. I eventually tracked it down to the fact that I had forgotten to call MagickResetIterator after reading in the images and before calling MagickEvaluateImages.
This is the code:

Code: Select all

#define MSG(s) MessageBox(NULL,s,"",MB_OK)
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <wand/magick_wand.h>

void test_wand(LPTSTR lpCmdLine)
{
	MagickWand *mw = NULL;
	MagickWand *ew = NULL;
	MagickWandGenesis();

	mw = NewMagickWand();
	MagickReadImage(mw,"http://www.imagemagick.org/Usage/compose/tile_water.jpg");
	MagickReadImage(mw,"http://www.imagemagick.org/Usage/compose/tile_aqua.jpg");
//MSG("Files read");

//>>> THIS IS ESSENTIAL !!! It will crash when this is commented
//	MagickResetIterator(mw);

	ew = MagickEvaluateImages(mw,MeanEvaluateOperator);
//MSG("Done evaluate");

	if(ew == NULL) {
		MSG("MagickEvaluateImages returned NULL");
		if(mw)mw = DestroyMagickWand(mw);
		return;
	}
	MagickWriteImage(ew,"evaluateimages_tiles.jpg");

	/* Clean up */
	if(mw)mw = DestroyMagickWand(mw);
	if(ew)ew = DestroyMagickWand(ew);
	MagickWandTerminus();
}
I haven't figured out precisely what is wrong but I suspect that the iterator is at the end of the image list and that the code doesn't check for this before it proceeds. Presumably MagickEvaluateImages should return NULL if there isn't at least one image in the list.
It is possible that MagickSmushImages and MagickCombineImages have the same problem.

I haven't installed V7 yet but a brief look at the code suggests that it has the same problem.
Are you still updating/patching V6?

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
Post Reply