Commit 184dd4e82 for imagemagick.org

commit 184dd4e82ff4cea4b848dd2710f4805fa6e4a516
Author: Dirk Lemstra <dirk@lemstra.org>
Date:   Sun Dec 6 21:42:22 2026 +0100

    Encode per row in the palm encoder.

diff --git a/coders/palm.c b/coders/palm.c
index 478f39d00..5d880e20f 100644
--- a/coders/palm.c
+++ b/coders/palm.c
@@ -753,6 +753,9 @@ static MagickBooleanType WritePALMImage(const ImageInfo *image_info,
   unsigned char
     byte,
     color,
+    *data_ptr,
+    *encoded_ptr,
+    *encoded_row,
     *last_row,
     *one_row,
     *ptr,
@@ -958,6 +961,20 @@ static MagickBooleanType WritePALMImage(const ImageInfo *image_info,
         quantize_info=DestroyQuantizeInfo(quantize_info);
         ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
       }
+    encoded_row=(unsigned char *) NULL;
+    if (flags & PALM_IS_COMPRESSED_FLAG)
+      {
+        encoded_row=(unsigned char *) AcquireQuantumMemory(bytes_per_row,
+          2*sizeof(*encoded_row));
+        if (encoded_row == (unsigned char *) NULL)
+          {
+            one_row=(unsigned char *) RelinquishMagickMemory(one_row);
+            if (last_row != (unsigned char *) NULL)
+              last_row=(unsigned char *) RelinquishMagickMemory(last_row);
+            quantize_info=DestroyQuantizeInfo(quantize_info);
+            ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
+          }
+      }
     for (y=0; y < (ssize_t) image->rows; y++)
     {
       ptr=one_row;
@@ -1012,6 +1029,7 @@ static MagickBooleanType WritePALMImage(const ImageInfo *image_info,
         }
       if (image_info->compression == RLECompression)
         {
+          encoded_ptr=encoded_row;
           x=0;
           while (x < (ssize_t) bytes_per_row)
           {
@@ -1023,38 +1041,51 @@ static MagickBooleanType WritePALMImage(const ImageInfo *image_info,
               count++;
               x++;
             }
-            (void) WriteBlobByte(image,(unsigned char) count);
-            (void) WriteBlobByte(image,byte);
+            *encoded_ptr++=(unsigned char) count;
+            *encoded_ptr++=byte;
           }
+          if (WriteBlob(image,(size_t) (encoded_ptr-encoded_row),encoded_row) !=
+              (ssize_t) (encoded_ptr-encoded_row))
+            {
+              status=MagickFalse;
+              break;
+            }
         }
       else
         if (image_info->compression == FaxCompression)
           {
-            char
-              tmpbuf[8],
-              *tptr;
-
+            encoded_ptr=encoded_row;
             for (x=0;  x < (ssize_t) bytes_per_row; x+=8)
             {
-              tptr = tmpbuf;
+              data_ptr=encoded_ptr+1;
               for (bit=0, byte=0; bit < (int) MagickMin(8L,(ssize_t) bytes_per_row-x); bit++)
               {
                 if ((y == 0) || (last_row[x + bit] != one_row[x + bit]))
                   {
                     byte |= (unsigned char) (1 << (7 - bit));
-                    *tptr++ = (char) one_row[x + bit];
+                    *data_ptr++=one_row[x+bit];
                   }
               }
-              (void) WriteBlobByte(image, byte);
-              (void) WriteBlob(image,(size_t) (tptr-tmpbuf),(unsigned char *)
-                tmpbuf);
+              *encoded_ptr=byte;
+              encoded_ptr=data_ptr;
             }
             (void) memcpy(last_row,one_row,bytes_per_row);
+            if (WriteBlob(image,(size_t) (encoded_ptr-encoded_row),encoded_row) != (ssize_t) (encoded_ptr-encoded_row))
+              {
+                status=MagickFalse;
+                break;
+              }
           }
         else
-          (void) WriteBlob(image,bytes_per_row,one_row);
+          if (WriteBlob(image,bytes_per_row,one_row) != (ssize_t) bytes_per_row)
+            {
+              status=MagickFalse;
+              break;
+            }
     }
     one_row=(unsigned char *) RelinquishMagickMemory(one_row);
+    if (encoded_row != (unsigned char *) NULL)
+      encoded_row=(unsigned char *) RelinquishMagickMemory(encoded_row);
     if (last_row != (unsigned char *) NULL)
       last_row=(unsigned char *) RelinquishMagickMemory(last_row);
     if (status == MagickFalse)