Possible race condition?

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
mkoppanen
Posts: 309
Joined: 2007-06-09T07:06:32-07:00

Possible race condition?

Post by mkoppanen »

Testing the following imagick code I get an occasional segfault:

Code: Select all

<?php
$combined = new Imagick();
$combined->readImage("floodfillpaint_intermediate.jpg");

/* The target pixel to paint */
$x = 1;
$y = 1;

/* Get the color we are painting */
$target = $combined->getImagePixelColor($x, $y);

/* Paint */
$combined->floodfillPaintImage("black", 1, $target, $x, $y, false);

/* Save the result */
$combined->writeImage("floodfillpaint_result.jpg");
The backtrace looks like following:

Code: Select all

0x00007ff25fa76d6e in ?? () from /usr/lib/libgomp.so.1
(gdb) bt
#0  0x00007ff25fa76d6e in ?? () from /usr/lib/libgomp.so.1
#1  0x00007ff25fa75846 in ?? () from /usr/lib/libgomp.so.1
#2  0x00007ff262023f9a in start_thread () from /lib/libpthread.so.0
#3  0x00007ff26295156d in clone () from /lib/libc.so.6
#4  0x0000000000000000 in ?? ()
(gdb)
Testing the almost the same thing in MagickWand code does NOT segfault:

Code: Select all

#include <stdio.h>
#include <wand/MagickWand.h>

int main() {

	MagickWand *image;
	PixelWand *source, *target;

	MagickWandGenesis();
	
	image  = NewMagickWand();
	source = NewPixelWand();
	target = NewPixelWand();
	
	MagickReadImage(image, "floodfillpaint_intermediate.jpg");
	
	PixelSetColor(source, "red");
	PixelSetColor(target, "black");
	
	MagickGetImagePixelColor(image, 1, 1, source);
	MagickFloodfillPaintImage(image, DefaultChannels, target, 1, source, 1, 1, MagickFalse);
	MagickWriteImage(image, "result.jpg");
	
	DestroyMagickWand(image);
	DestroyPixelWand(source);
	DestroyPixelWand(target);
	
	MagickWandTerminus();
	return 0;
}
After this I tested the Imagick code with ImageMagick compiled with --disable-openmp and it does not segfault.
Mikko Koppanen
My blog: http://valokuva.org
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Possible race condition?

Post by magick »

The stack trace suggests the bug is in libgomp, not ImageMagick. ImageMagick has little control over OpenMP. We declare a loop eligible for threading and libgomp does all the work. We have run across a few versions of libgomp that are buggy and generally an upgrade or downgrade of the libgomp version fixes the problem. You of course can turn off OpenMP support within ImageMagick as well as you have already done.
Post Reply