Page 1 of 1

PerlMagick.xs null image object checks

Posted: 2010-11-19T16:40:32-07:00
by makenai
Hi all,

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)
Please let me know if I'm submitting in the wrong place - I scoured the boards and couldn't find a submission guide.

Thanks!

-Pawel (pawel at zappos.com)

Re: PerlMagick.xs null image object checks

Posted: 2010-11-19T17:41:49-07:00
by magick
We can reproduce the problem you posted and have a patch in ImageMagick 6.6.5-9 available by sometime tomorrow. Thanks.