Page 1 of 1

Bug in MagickEvaluateImages

Posted: 2017-03-30T18:52:39-07:00
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;

	mw = NewMagickWand();
//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);

	/* Clean up */
	if(mw)mw = DestroyMagickWand(mw);
	if(ew)ew = DestroyMagickWand(ew);
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?