Commit 3a1f56277 for imagemagick.org

commit 3a1f56277760f042cac2172925f74ada2597a305
Author: Cristy <urban-warrior@imagemagick.org>
Date:   Wed Dec 2 18:35:24 2026 -0500

    use SetPixelGray() and step by GetPixelChannels()

diff --git a/coders/strimg.c b/coders/strimg.c
index 1217dc4a1..f724b26a9 100644
--- a/coders/strimg.c
+++ b/coders/strimg.c
@@ -57,6 +57,7 @@
 #include "MagickCore/memory_.h"
 #include "MagickCore/monitor.h"
 #include "MagickCore/monitor-private.h"
+#include "MagickCore/pixel-accessor.h"
 #include "MagickCore/property.h"
 #include "MagickCore/quantum.h"
 #include "MagickCore/quantum-private.h"
@@ -112,6 +113,9 @@ static Image *ReadSTRIMGImage(const ImageInfo *image_info,
   Quantum
     *q;

+  size_t
+    length;
+
   ssize_t
     x;

@@ -126,13 +130,22 @@ static Image *ReadSTRIMGImage(const ImageInfo *image_info,
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
       image_info->filename);
   image=AcquireImage(image_info,exception);
+  if (image == (Image *) NULL)
+    return((Image *) NULL);
   string=InterpretImageProperties((ImageInfo *) image_info,image,
     image_info->filename,exception);
   if (string == (char *) NULL)
     return(DestroyImageList(image));
+  length=strlen(string);
+  if (length == 0)
+    {
+      string=DestroyString(string);
+      ThrowReaderException(CorruptImageError,"ImproperImageHeader");
+    }
   image->depth=8;
   image->colorspace=GRAYColorspace;
-  image->columns=strlen(string);
+  image->type=GrayscaleType;
+  image->columns=length;
   image->rows=1;
   if (image_info->ping != MagickFalse)
     {
@@ -158,7 +171,10 @@ static Image *ReadSTRIMGImage(const ImageInfo *image_info,
       return(DestroyImageList(image));
     }
   for (x=0; x < (ssize_t) image->columns; x++)
-    q[x]=ScaleCharToQuantum((unsigned char) string[x]);
+  {
+    SetPixelGray(image,ScaleCharToQuantum((unsigned char) string[x]),q);
+    q+=GetPixelChannels(image);
+  }
   string=DestroyString(string);
   if (SyncAuthenticPixels(image,exception) == MagickFalse)
     {
@@ -204,7 +220,7 @@ ModuleExport size_t RegisterSTRIMGImage(void)
   entry->decoder=(DecodeImageHandler *) ReadSTRIMGImage;
   entry->encoder=(EncodeImageHandler *) WriteSTRIMGImage;
   entry->flags|=CoderRawSupportFlag;
-  entry->flags^=CoderAdjoinFlag;
+  entry->flags&=~CoderAdjoinFlag;
   (void) RegisterMagickInfo(entry);
   return(MagickImageCoderSignature);
 }
@@ -244,7 +260,8 @@ ModuleExport void UnregisterSTRIMGImage(void)
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  WriteSTRIMGImage() writes an image as a string.
+%  WriteSTRIMGImage() writes an image as a string.  Pixels are written as
+%  8-bit gray values, row after row, with no separator between rows.
 %
 %  The format of the WriteSTRIMGImage method is:
 %
@@ -314,7 +331,10 @@ static MagickBooleanType WriteSTRIMGImage(const ImageInfo *image_info,

     p=GetVirtualPixels(image,0,y,image->columns,1,exception);
     if (p == (const Quantum *) NULL)
-      break;
+      {
+        status=MagickFalse;
+        break;
+      }
     length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
       GrayQuantum,pixels,exception);
     count=WriteBlob(image,length,pixels);