Commit 8db7b7a05 for imagemagick.org
commit 8db7b7a057450680dfcc294646223da66b48bfba
Author: Cristy <urban-warrior@imagemagick.org>
Date: Fri Dec 4 18:41:50 2026 -0500
ReadHRZImage now masks each 6-bit HRZ sample and scales it with bit replication
diff --git a/coders/hrz.c b/coders/hrz.c
index 0929a7662..5089eedb8 100644
--- a/coders/hrz.c
+++ b/coders/hrz.c
@@ -92,6 +92,19 @@ static MagickBooleanType
% o exception: return any errors or warnings in this structure.
%
*/
+static inline unsigned char ScaleHRZToChar(const unsigned char value)
+{
+ unsigned char
+ sample;
+
+ /*
+ HRZ samples are 6-bit (0..63); clamp malformed input and replicate the
+ high bits so that 63 maps to 255 rather than 252 (or wrapping past 255).
+ */
+ sample=(unsigned char) (value & 0x3f);
+ return((unsigned char) ((sample << 2) | (sample >> 4)));
+}
+
static Image *ReadHRZImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
Image
@@ -162,17 +175,23 @@ static Image *ReadHRZImage(const ImageInfo *image_info,ExceptionInfo *exception)
p=pixels;
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
if (q == (Quantum *) NULL)
- break;
+ {
+ status=MagickFalse;
+ break;
+ }
for (x=0; x < (ssize_t) image->columns; x++)
{
- SetPixelRed(image,ScaleCharToQuantum(4**p++),q);
- SetPixelGreen(image,ScaleCharToQuantum(4**p++),q);
- SetPixelBlue(image,ScaleCharToQuantum(4**p++),q);
+ SetPixelRed(image,ScaleCharToQuantum(ScaleHRZToChar(*p++)),q);
+ SetPixelGreen(image,ScaleCharToQuantum(ScaleHRZToChar(*p++)),q);
+ SetPixelBlue(image,ScaleCharToQuantum(ScaleHRZToChar(*p++)),q);
SetPixelAlpha(image,OpaqueAlpha,q);
q+=(ptrdiff_t) GetPixelChannels(image);
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
- break;
+ {
+ status=MagickFalse;
+ break;
+ }
if (SetImageProgress(image,LoadImageTag,y,image->rows) == MagickFalse)
break;
}
@@ -310,7 +329,10 @@ static MagickBooleanType WriteHRZImage(const ImageInfo *image_info,Image *image,
return(status);
hrz_image=ResizeImage(image,256,240,image->filter,exception);
if (hrz_image == (Image *) NULL)
- return(MagickFalse);
+ {
+ (void) CloseBlob(image);
+ return(MagickFalse);
+ }
(void) TransformImageColorspace(hrz_image,sRGBColorspace,exception);
/*
Allocate memory for pixels.
@@ -329,7 +351,10 @@ static MagickBooleanType WriteHRZImage(const ImageInfo *image_info,Image *image,
{
p=GetVirtualPixels(hrz_image,0,y,hrz_image->columns,1,exception);
if (p == (const Quantum *) NULL)
- break;
+ {
+ status=MagickFalse;
+ break;
+ }
q=pixels;
for (x=0; x < (ssize_t) hrz_image->columns; x++)
{