Index: GraphicsMagick-1.2.5/coders/palm.c
===================================================================
--- GraphicsMagick-1.2.5.orig/coders/palm.c	2008-06-11 02:07:38.000000000 +0200
+++ GraphicsMagick-1.2.5/coders/palm.c	2016-06-14 15:24:12.749897545 +0200
@@ -358,7 +358,7 @@ static unsigned int
 %
 %
 */
-static int FindColor(PixelPacket *pixel)
+static long FindColor(PixelPacket *pixel)
 {
   register long
     i;
@@ -509,7 +509,7 @@ static Image *ReadPALMImage(const ImageI
             for(i = 0; i < (long) count; i++)
               {
                 (void) ReadBlobByte(image);
-                index=255 - i;
+                index=(unsigned int)(255 - i);
                 VerifyColormapIndex(image,index);
                 image->colormap[index].red = ScaleCharToQuantum(ReadBlobByte(image));
                 image->colormap[index].green = ScaleCharToQuantum(ReadBlobByte(image));
@@ -531,7 +531,7 @@ static Image *ReadPALMImage(const ImageI
                 transpix.green = (unsigned char) (ReadBlobByte(image) * MaxRGB / 63);
                 transpix.blue = (unsigned char) (ReadBlobByte(image) * MaxRGB / 31);
               }
-            index=255 - i;
+            index=(unsigned int)(255 - i);
             VerifyColormapIndex(image,index);
             image->colormap[index].red = ScaleCharToQuantum(PalmPalette[i][0]);
             image->colormap[index].green = ScaleCharToQuantum(PalmPalette[i][1]);
@@ -553,13 +553,13 @@ static Image *ReadPALMImage(const ImageI
       (void) SetImageType(image, TrueColorType);
     }
 
-  one_row = MagickAllocateMemory(unsigned char *,bytes_per_row);
+  one_row = MagickAllocateMemory(unsigned char *,Max(bytes_per_row,2*image->columns));
   if (one_row == (unsigned char *) NULL)
     ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,image);
   if (compressionType == PALM_COMPRESSION_SCANLINE)
-    lastrow = MagickAllocateMemory(unsigned char *,bytes_per_row);
+    lastrow = MagickAllocateMemory(unsigned char *,Max(bytes_per_row,2*image->columns));
 
-  mask = (1l << bits_per_pixel) - 1;
+  mask = (unsigned long) (1U << bits_per_pixel) - 1;
 
   for(y = 0; y < (long) image->rows; y++)
     {
@@ -584,7 +584,7 @@ static Image *ReadPALMImage(const ImageI
                 for (i = 0; i < (long) bytes_per_row; i += 8)
                   {
                     count = ReadBlobByte(image);
-                    byte = Min(bytes_per_row - i, 8);
+                    byte = (unsigned long) Min(bytes_per_row - i, 8);
                     for (bit = 0; bit < byte; bit++)
                       {
                         if (y == 0 || count & (1 << (7 - bit)))
@@ -759,9 +759,6 @@ ModuleExport void UnregisterPALMImage(vo
 */
 static unsigned int WritePALMImage(const ImageInfo *image_info,Image *image)
 {
-  int
-    y;
-
   QuantizeInfo
     quantize_info;
 
@@ -803,6 +800,9 @@ static unsigned int WritePALMImage(const
   ImageCharacteristics
     characteristics;
 
+  long
+    y;
+
   /*
     Open output image file.
   */
@@ -939,7 +939,7 @@ static unsigned int WritePALMImage(const
     ThrowWriterException(ResourceLimitError,MemoryAllocationFailed,image);
 
   transpix.red=transpix.green=transpix.blue=0;
-  for (y=0; y < (int) image->rows; y++)
+  for (y=0; y < (long) image->rows; y++)
     {
       ptr = one_row;
       (void) memset(ptr, 0, bytes_per_row);
@@ -949,7 +949,7 @@ static unsigned int WritePALMImage(const
       indexes=GetIndexes(image);
       if(bits_per_pixel == 16)
         {
-          for (x=0; x < (int) image->columns; x++)
+          for (x=0; x < (long) image->columns; x++)
             {
               color16 = (unsigned short) (((p->red * 31) / MaxRGB) << 11
                                           | ((p->green * 63) / MaxRGB) << 5
@@ -971,7 +971,7 @@ static unsigned int WritePALMImage(const
         {
           byte = 0x00;
           bit = (unsigned char) (8 - bits_per_pixel);
-          for (x=0; x < (int) image->columns; x++)
+          for (x=0; x < (long) image->columns; x++)
             {
               if(bits_per_pixel < 8) /* Make sure we use the entire colorspace for bits_per_pixel */
                 color = (unsigned char) (indexes[x] * ((1 << bits_per_pixel) - 1) /
