odd run lengths for BI_RLE4 compressed BMP files were handled incorrectly
authorTony Cook <tony@develop-help.com>
Tue, 24 Apr 2012 09:23:21 +0000 (19:23 +1000)
committerTony Cook <tony@develop-help.com>
Tue, 24 Apr 2012 09:23:21 +0000 (19:23 +1000)
bmp.c
xtestimg/bmp/unalign4rle.bmp [new file with mode: 0644]
xtestimg/bmp/unalign4rle2.bmp [new file with mode: 0644]

diff --git a/bmp.c b/bmp.c
index 6f82f2f..4f770b8 100644 (file)
--- a/bmp.c
+++ b/bmp.c
@@ -967,20 +967,18 @@ read_4bit_bmp(io_glue *ig, int xsize, int ysize, int clr_used,
          myfree(packed);
          myfree(line);
          i_push_error(0, "invalid data during decompression");
-         mm_log((1, "read 4-bit: scanline overflow x %d + count %d vs xsize %d (y %d)\n",
-                 (int)x, count, (int)xsize, (int)y));
+         mm_log((1, "read 4-bit: scanline overflow x %d + count %d vs xlimit %d (y %d)\n",
+                 (int)x, count, (int)xlimit, (int)y));
          i_img_destroy(im);
          return NULL;
        }
-        line[0] = packed[1] >> 4;
-        line[1] = packed[1] & 0x0F;
-        for (i = 0; i < count; i += 2) {
-          if (i < count-1) 
-            i_ppal(im, x, x+2, y, line);
-          else
-            i_ppal(im, x, x+(count-i), y, line);
-          x += 2;
-        }
+       /* fill in the line */
+       for (i = 0; i < count; i += 2)
+         line[i] = packed[1] >> 4;
+       for (i = 1; i < count; i += 2)
+         line[i] = packed[1] & 0x0F;
+       i_ppal(im, x, x+count, y, line);
+       x += count;
       } else {
         switch (packed[1]) {
         case BMPRLE_ENDOFLINE:
@@ -1019,6 +1017,8 @@ read_4bit_bmp(io_glue *ig, int xsize, int ysize, int clr_used,
            myfree(packed);
            myfree(line);
            i_push_error(0, "invalid data during decompression");
+           mm_log((1, "read 4-bit: scanline overflow (unpacked) x %d + count %d vs xlimit %d (y %d)\n",
+                 (int)x, count, (int)xlimit, (int)y));
            i_img_destroy(im);
            return NULL;
          }
diff --git a/xtestimg/bmp/unalign4rle.bmp b/xtestimg/bmp/unalign4rle.bmp
new file mode 100644 (file)
index 0000000..7e8b3df
Binary files /dev/null and b/xtestimg/bmp/unalign4rle.bmp differ
diff --git a/xtestimg/bmp/unalign4rle2.bmp b/xtestimg/bmp/unalign4rle2.bmp
new file mode 100644 (file)
index 0000000..14d3528
Binary files /dev/null and b/xtestimg/bmp/unalign4rle2.bmp differ