ImageMagick interprets PGM header incorrectly

Bug #346474 reported by pipe
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
imagemagick (Ubuntu)
Expired
Medium
Unassigned

Bug Description

Binary package hint: imagemagick

Ubuntu 8.10
imagemagick 7:6.3.7.9.dfsg1-2ubuntu3

When reading a PGM-P5 (binary) image with a maxval of 256, the 'convert' and 'display' utility, and likely the rest, will interpret each pixel as one byte, when it should interpret each pixel as two bytes since 256 is more than 255. This causes vertical stripes and other nastiness in the image. If maxval is set to 257, everything works as it should.

Apparently you can only submit one attachment in this bugtracker so users have to host their own files. Download example images from:
http://natrox.ath.cx/imagemagick/lena-255.pgm
http://natrox.ath.cx/imagemagick/lena-256.pgm
http://natrox.ath.cx/imagemagick/lena-257.pgm

Display with imagemagick:
$ display -sample 400% lena-255.pgm
$ display -sample 400% lena-256.pgm
$ display -sample 400% lena-257.pgm

255 and 257 works, 256 breaks.

Revision history for this message
pipe (pipatron) wrote :

A patch that solves this issue:

pipe@vitamin:~/src/imagemagick-6.3.7.9.dfsg1$ diff -u coders/orig/pnm.c coders/pnm.c
--- coders/orig/pnm.c 2007-12-08 01:13:40.000000000 +0100
+++ coders/pnm.c 2009-03-24 21:54:47.000000000 +0100
@@ -417,7 +417,7 @@
       ThrowReaderException(CorruptImageError,"NegativeOrZeroImageSize");
     if (max_value >= 65536)
       ThrowReaderException(CorruptImageError,"ImproperImageHeader");
- for (image->depth=1; (1UL << image->depth) < max_value; image->depth++);
+ for (image->depth=1; (1UL << image->depth) <= max_value; image->depth++);
     scale=(Quantum *) NULL;
     if (image->storage_class == PseudoClass)
       if (AllocateImageColormap(image,image->colors) == MagickFalse)

Revision history for this message
Brian Murray (brian-murray) wrote :

Thanks for taking the time to report this bug and including a patch too. I've tried recreating this on the Jackalope using package version 7:6.4.5.4.dfsg1-1ubuntu3 and was unable to. Looking at the source code of imagemagick it seems to have change a bit too:

    if (max_value >= 65536)
      ThrowReaderException(CorruptImageError,"ImproperImageHeader");
    for (depth=1; GetQuantumRange(depth) < max_value; depth++) ;
    image->depth=depth;
    if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0))
      if (image->scene >= (image_info->scene+image_info->number_scenes-1))

Since you wrote the patch, do you think this might resolve the bug? Thanks in advance.

Changed in imagemagick (Ubuntu):
status: New → Incomplete
Changed in imagemagick (Ubuntu):
status: Incomplete → New
status: New → Triaged
importance: Undecided → Medium
Changed in imagemagick (Ubuntu):
status: Triaged → Fix Committed
Changed in imagemagick:
status: New → Fix Released
Revision history for this message
Mathew Hodson (mhodson) wrote :

Was this fixed upstream?

affects: imagemagick → ubuntu
no longer affects: ubuntu
Changed in imagemagick (Ubuntu):
status: Fix Committed → Incomplete
Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for imagemagick (Ubuntu) because there has been no activity for 60 days.]

Changed in imagemagick (Ubuntu):
status: Incomplete → Expired
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.