We're using ImageMagick / PerlMagick heavily in batch image generation. I noticed that sometimes on a gravity call, we'd get a null pointer exception. Many places in the PerlMagick.xs do checks, but there were a few that left it out and assumed that the image object would never be null. I've gone through and added checks to the missing areas. With this fix in place, we no longer get random crashes that have been puzzling us.
Patch:
Code: Select all
Index: PerlMagick/Magick.xs
===================================================================
--- PerlMagick/Magick.xs (revision 3169)
+++ PerlMagick/Magick.xs (working copy)
@@ -4430,6 +4430,8 @@
}
if (LocaleCompare(attribute,"compression") == 0)
{
+ if (image == (Image *) NULL)
+ break;
j=info ? info->image_info->compression : image->compression;
if (info)
if (info->image_info->compression == UndefinedCompression)
@@ -4592,6 +4594,8 @@
}
if (LocaleCompare(attribute,"endian") == 0)
{
+ if (image == (Image *) NULL)
+ break;
j=info ? info->image_info->endian : image->endian;
s=newSViv(j);
(void) sv_setpv(s,MagickOptionToMnemonic(MagickEndianOptions,j));
@@ -4632,6 +4636,8 @@
}
if (LocaleCompare(attribute,"filter") == 0)
{
+ if (image == (Image *) NULL)
+ break;
s=newSViv(image->filter);
(void) sv_setpv(s,MagickOptionToMnemonic(MagickFilterOptions,
image->filter));
@@ -4696,6 +4702,8 @@
}
if (LocaleCompare(attribute,"gravity") == 0)
{
+ if (image == (Image *) NULL)
+ break;
s=newSViv(image->gravity);
(void) sv_setpv(s,
MagickOptionToMnemonic(MagickGravityOptions,image->gravity));
@@ -4852,6 +4860,8 @@
}
if (LocaleCompare(attribute,"interlace") == 0)
{
+ if (image == (Image *) NULL)
+ break;
j=info ? info->image_info->interlace : image->interlace;
s=newSViv(j);
(void) sv_setpv(s,MagickOptionToMnemonic(MagickInterlaceOptions,
@@ -5005,6 +5015,8 @@
{
if (LocaleCompare(attribute,"orientation") == 0)
{
+ if (image == (Image *) NULL)
+ break;
j=info ? info->image_info->orientation : image->orientation;
s=newSViv(j);
(void) sv_setpv(s,MagickOptionToMnemonic(MagickOrientationOptions,
@@ -5137,6 +5149,8 @@
{
if (LocaleCompare(attribute,"rendering-intent") == 0)
{
+ if (image == (Image *) NULL)
+ break;
s=newSViv(image->rendering_intent);
(void) sv_setpv(s,MagickOptionToMnemonic(MagickIntentOptions,
image->rendering_intent));
@@ -5300,6 +5314,8 @@
{
if (LocaleCompare(attribute,"units") == 0)
{
+ if (image == (Image *) NULL)
+ break;
j=info ? info->image_info->units : image->units;
if (info)
if (info->image_info->units == UndefinedResolution)
Thanks!
-Pawel (pawel at zappos.com)