Skip to content

Commit

Permalink
Cosmetic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristy committed Jul 21, 2017
1 parent 1fdc09d commit 0b13c96
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
11 changes: 9 additions & 2 deletions magick/attribute.c
Expand Up @@ -1288,8 +1288,15 @@ MagickExport MagickBooleanType SetImageType(Image *image,const ImageType type)
case BilevelType:
{
if (SetImageMonochrome(image,&image->exception) == MagickFalse)
status=AutoThresholdImage(image,UndefinedThresholdMethod,
&image->exception);
{
status=TransformImageColorspace(image,GRAYColorspace);
(void) NormalizeImage(image);
quantize_info=AcquireQuantizeInfo(image_info);
quantize_info->number_colors=2;
quantize_info->colorspace=GRAYColorspace;
status=QuantizeImage(quantize_info,image);
quantize_info=DestroyQuantizeInfo(quantize_info);
}
image->matte=MagickFalse;
break;
}
Expand Down
10 changes: 8 additions & 2 deletions magick/enhance.c
Expand Up @@ -1178,8 +1178,14 @@ MagickExport MagickBooleanType ContrastStretchImageChannel(Image *image,
sizeof(*stretch_map));
if ((histogram == (MagickPixelPacket *) NULL) ||
(stretch_map == (QuantumPixelPacket *) NULL))
ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
image->filename);
{
if (stretch_map != (double *) NULL)
stretch_map=(double *) RelinquishMagickMemory(stretch_map);
if (histogram != (double *) NULL)
histogram=(double *) RelinquishMagickMemory(histogram);
ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
image->filename);
}
/*
Form histogram.
*/
Expand Down
6 changes: 3 additions & 3 deletions magick/quantize.c
Expand Up @@ -110,8 +110,8 @@
%
% Sr, Sg, Sb: Sums of the red, green, and blue component values for all
% pixels not classified at a lower depth. The combination of these sums
% and n2 will ultimately characterize the mean color of a set of
% pixels represented by this node.
% and n2 will ultimately characterize the mean color of a set of pixels
% represented by this node.
%
% E: the distance squared in RGB space between each pixel contained
% within a node and the nodes' center. This represents the
Expand Down Expand Up @@ -844,7 +844,7 @@ static MagickBooleanType ClassifyImageColors(CubeInfo *cube_info,
error.opacity=QuantumScale*(pixel.opacity-mid.opacity);
distance=(double) (error.red*error.red+error.green*error.green+
error.blue*error.blue+error.opacity*error.opacity);
if (IsNaN(distance))
if (IsNaN(distance) != MagickFalse)
distance=0.0;
node_info->quantize_error+=count*sqrt(distance);
cube_info->root->quantize_error+=node_info->quantize_error;
Expand Down

2 comments on commit 0b13c96

@bastien-roucaries
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not cosmetic change but security one due to free memory. Could you detail these changes

@mikayla-grace
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only security issue would be a potential memory leak if memory could not be allocated for one of histogram or stretch_map. If both cannot be allocated, there is no memory leak. If only one is allocated and the other fails, there is a memory leak of the one that could not be allocated. There is very little chance the allocations would fail, so its low risk.

The other patch was to revert code for creating monochrome images. We found the source of the problem elsewhere so we restored our original code.

The last patch is cosmetic.

Yes, we should have submitted separate commit-- likely fatigue. We've been swamped with issues lately.

And in case we have overlooked it-- thanks for pushing these patches to the Linux mainstream releases of older versions of ImageMagick. Given our small development team and given we're trying to maintain about 600,000 lines of code, we could not possibly keep those releases up to date with patches without your assistance.

Please sign in to comment.