ImageMagick interprets PGM header incorrectly
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.
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://
http://
http://
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.
Related branches
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 |
A patch that solves this issue:
pipe@vitamin: ~/src/imagemagi ck-6.3. 7.9.dfsg1$ diff -u coders/orig/pnm.c coders/pnm.c
ThrowReaderExce ption(CorruptIm ageError, "NegativeOrZero ImageSize" );
ThrowReaderExce ption(CorruptIm ageError, "ImproperImageH eader") ; >storage_ class == PseudoClass) olormap( image,image- >colors) == MagickFalse)
--- 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 @@
if (max_value >= 65536)
- 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-
if (AllocateImageC