[prev in list] [next in list] [prev in thread] [next in thread]
List: graphicsmagick-commit
Subject: [GM-commit] GraphicsMagick: Fixes for issues noted while testing under reduc...
From: GraphicsMagick Commits <graphicsmagick-commit () lists ! sourceforge ! net>
Date: 2020-12-22 1:41:34
Message-ID: mailman.192700.1608601328.1839.graphicsmagick-commit () lists ! sourceforge ! net
[Download RAW message or body]
changeset b2b75f418d41 in /hg/GraphicsMagick
details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=b2b75f418d41
summary: Fixes for issues noted while testing under reduced memory limits.
diffstat:
ChangeLog | 30 ++++++++
coders/fax.c | 28 ++++---
coders/jp2.c | 4 +-
common.shi.in | 4 +
magick/command.c | 55 +++++++--------
magick/compress.c | 169 +++++++++++++++++++++++++----------------------
magick/decorate.c | 174 +++++++++++++++++++++++++------------------------
magick/effect.c | 3 +-
magick/image.c | 2 +-
tests/constitute.c | 5 +-
wand/drawtest.c | 4 +-
www/Changelog.html | 21 ++++++
www/api/decorate.html | 2 +-
www/api/effect.html | 4 +-
www/api/image.html | 4 +-
15 files changed, 292 insertions(+), 217 deletions(-)
diffs (truncated from 829 to 500 lines):
diff -r f226cbdadb83 -r b2b75f418d41 ChangeLog
--- a/ChangeLog Mon Dec 21 08:24:40 2020 -0600
+++ b/ChangeLog Mon Dec 21 19:41:29 2020 -0600
@@ -1,5 +1,35 @@
2020-12-21 Bob Friesenhahn <bfriesen@simple.dallas.tx.us>
+ * coders/jp2.c (BlobWrite): Update Jasper stream OPs callback
+ function signatures to exactly match latest jas_stream_ops_t
+ definition. This avoids an annoying warning when using Jasper
+ 2.0.12 but now causes annoying warnings when using 1.900.1.
+
+ * magick/decorate.c (FrameImage): Skip attempting to render top or
+ bottom of ornamental border if its height is zero.
+
+ * magick/image.c (CloneImage): Set image signature right away in
+ case it needs to be destroyed while it is being constructed.
+
+ * wand/drawtest.c (main): MagickGetFilename() allocates a new
+ string so make sure to free it.
+
+ * tests/constitute.c (main): Destroy ExceptionInfo to avoid memory
+ leak if an exception was thrown.
+
+ * magick/effect.c (EdgeImage): Fix null pointer dereference if
+ edge image failed to be created.
+
+ * magick/compress.c (HuffmanEncode2Image): Fix error handling
+ issues.
+
+ * magick/command.c (CompareImageCommand): Fix memory leaks when an
+ input image failed to be read.
+ (CompositeImageCommand): Fix memory leaks when an input image
+ failed to be read.
+
+ * coders/fax.c (WriteFAXImage): Fix error handling.
+
* coders/mpc.c (ReadMPCImage): Use correct deallocator for page
geometry. Fixes oss-fuzz 28853 "Heap-buffer-overflow READ {*} -
_MagickReallocateResourceLimitedMemory".
diff -r f226cbdadb83 -r b2b75f418d41 coders/fax.c
--- a/coders/fax.c Mon Dec 21 08:24:40 2020 -0600
+++ b/coders/fax.c Mon Dec 21 19:41:29 2020 -0600
@@ -273,8 +273,8 @@
%
% A description of each parameter follows.
%
-% o status: Method WriteFAXImage return True if the image is written.
-% False is returned is there is a memory shortage or if the image file
+% o status: Method WriteFAXImage return MagickPass if the image is written.
+% MagickFail is returned is there is a memory shortage or if the image file
% fails to write.
%
% o image_info: Specifies a pointer to a ImageInfo structure.
@@ -283,12 +283,12 @@
%
%
*/
-static unsigned int WriteFAXImage(const ImageInfo *image_info,Image *image)
+static MagickPassFail WriteFAXImage(const ImageInfo *image_info,Image *image)
{
ImageInfo
*clone_info;
- unsigned int
+ MagickPassFail
status;
unsigned long
@@ -305,9 +305,9 @@
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
+ if (status == MagickFail)
+ ThrowWriterException(FileOpenError,UnableToOpenFile,image);
image_list_length=GetImageListLength(image);
- if (status == False)
- ThrowWriterException(FileOpenError,UnableToOpenFile,image);
clone_info=CloneImageInfo(image_info);
(void) strcpy(clone_info->magick,"FAX");
scene=0;
@@ -316,15 +316,19 @@
/*
Convert MIFF to monochrome.
*/
- (void) TransformColorspace(image,RGBColorspace);
- status=HuffmanEncodeImage(clone_info,image);
+ status &= TransformColorspace(image,RGBColorspace);
+ if (status != MagickPass)
+ break;
+ status &= HuffmanEncodeImage(clone_info,image);
+ if (status != MagickPass)
+ break;
if (image->next == (Image *) NULL)
break;
image=SyncNextImageInList(image);
- status=MagickMonitorFormatted(scene++,image_list_length,
- &image->exception,SaveImagesText,
- image->filename);
- if (status == False)
+ status &= MagickMonitorFormatted(scene++,image_list_length,
+ &image->exception,SaveImagesText,
+ image->filename);
+ if (status != MagickPass)
break;
} while (clone_info->adjoin);
DestroyImageInfo(clone_info);
diff -r f226cbdadb83 -r b2b75f418d41 coders/jp2.c
--- a/coders/jp2.c Mon Dec 21 08:24:40 2020 -0600
+++ b/coders/jp2.c Mon Dec 21 19:41:29 2020 -0600
@@ -276,7 +276,7 @@
*image;
} StreamManager;
-static int BlobRead(jas_stream_obj_t *object,char *buffer,const int length)
+static int BlobRead(jas_stream_obj_t *object,char *buffer,unsigned length)
{
size_t
count;
@@ -288,7 +288,7 @@
return ((int) count);
}
-static int BlobWrite(jas_stream_obj_t *object,char *buffer,const int length)
+static int BlobWrite(jas_stream_obj_t *object,const char *buffer,unsigned length)
{
size_t
count;
diff -r f226cbdadb83 -r b2b75f418d41 common.shi.in
--- a/common.shi.in Mon Dec 21 08:24:40 2020 -0600
+++ b/common.shi.in Mon Dec 21 19:41:29 2020 -0600
@@ -38,6 +38,10 @@
if test -z "$MAGICK_LIMIT_DISK" ; then
export MAGICK_LIMIT_DISK=0
fi
+# Enable debug traces for exceptions
+if test -z "MAGICK_DEBUG" ; then
+ export MAGICK_DEBUG=exception
+fi
printf "Resource Limits: MAGICK_LIMIT_MEMORY=%s MAGICK_LIMIT_WIDTH=%s \
MAGICK_LIMIT_HEIGHT=%s MAGICK_LIMIT_DISK=%s\n\n" "$MAGICK_LIMIT_MEMORY" \
"$MAGICK_LIMIT_WIDTH" "$MAGICK_LIMIT_HEIGHT" "$MAGICK_LIMIT_DISK"
set +a
diff -r f226cbdadb83 -r b2b75f418d41 magick/command.c
--- a/magick/command.c Mon Dec 21 08:24:40 2020 -0600
+++ b/magick/command.c Mon Dec 21 19:41:29 2020 -0600
@@ -2263,21 +2263,15 @@
*/
#define ThrowCompareException(code,reason,description) \
{ \
- DestroyImageList(compare_image); \
- DestroyImageList(difference_image); \
- DestroyImageList(reference_image); \
+ status=MagickFail; \
ThrowException(exception,code,reason,description); \
- LiberateArgumentList(argc,argv); \
- return(MagickFail); \
+ goto compare_cleanup_and_return; \
}
#define ThrowCompareException3(code,reason,description) \
{ \
- DestroyImageList(compare_image); \
- DestroyImageList(difference_image); \
- DestroyImageList(reference_image); \
+ status=MagickFail; \
ThrowException3(exception,code,reason,description); \
- LiberateArgumentList(argc,argv); \
- return(MagickFail); \
+ goto compare_cleanup_and_return; \
}
MagickExport MagickPassFail
CompareImageCommand(ImageInfo *image_info,
@@ -2754,13 +2748,19 @@
if (compare_image == (Image *) NULL)
{
if (exception->severity == UndefinedException)
- ThrowCompareException(OptionError,RequestDidNotReturnAnImage,
- (char *) NULL);
- return(MagickFail);
+ ThrowException(exception,OptionError,RequestDidNotReturnAnImage,(char *) \
NULL); + }
+ if (reference_image == (Image *) NULL)
+ {
+ if (exception->severity == UndefinedException)
+ ThrowException(exception,OptionError,MissingAnImageFilename,(char *) NULL);
}
if ((reference_image == (Image *) NULL) ||
(compare_image == (Image *) NULL))
- ThrowCompareException(OptionError,MissingAnImageFilename,(char *) NULL);
+ {
+ status=MagickFail;
+ goto compare_cleanup_and_return;
+ }
/*
Apply any user settings to images prior to compare.
@@ -2866,6 +2866,8 @@
}
}
+ compare_cleanup_and_return:
+
DestroyImageList(difference_image);
DestroyImageList(reference_image);
DestroyImageList(compare_image);
@@ -3116,23 +3118,15 @@
#define NotInitialized (unsigned int) (~0)
#define ThrowCompositeException(code,reason,description) \
{ \
- LiberateCompositeOptions(&option_info); \
- DestroyImageList(image); \
- DestroyImageList(composite_image); \
- DestroyImageList(mask_image); \
+ status=MagickFail; \
ThrowException(exception,code,reason,description); \
- LiberateArgumentList(argc,argv); \
- return(MagickFail); \
+ goto composite_cleanup_and_return; \
}
#define ThrowCompositeException3(code,reason,description) \
{ \
- LiberateCompositeOptions(&option_info); \
- DestroyImageList(image); \
- DestroyImageList(composite_image); \
- DestroyImageList(mask_image); \
+ status=MagickFail; \
ThrowException3(exception,code,reason,description); \
- LiberateArgumentList(argc,argv); \
- return(MagickFail); \
+ goto composite_cleanup_and_return; \
}
MagickExport MagickPassFail CompositeImageCommand(ImageInfo *image_info,
int argc,char **argv,char **metadata,ExceptionInfo *exception)
@@ -4095,9 +4089,9 @@
if (image == (Image *) NULL)
{
if (exception->severity == UndefinedException)
- ThrowCompositeException(OptionError,RequestDidNotReturnAnImage,
- (char *) NULL);
- return(MagickFail);
+ ThrowException(exception,OptionError,RequestDidNotReturnAnImage,(char *) \
NULL); + status=MagickFail;
+ goto composite_cleanup_and_return;
}
if (i != (argc-1))
ThrowCompositeException(OptionError,MissingAnImageFilename,(char *) NULL);
@@ -4122,6 +4116,9 @@
(void) ConcatenateString(&(*metadata),"\n");
MagickFreeMemory(text);
}
+
+ composite_cleanup_and_return:
+
LiberateCompositeOptions(&option_info);
DestroyImageList(composite_image);
DestroyImageList(mask_image);
diff -r f226cbdadb83 -r b2b75f418d41 magick/compress.c
--- a/magick/compress.c Mon Dec 21 08:24:40 2020 -0600
+++ b/magick/compress.c Mon Dec 21 19:41:29 2020 -0600
@@ -700,7 +700,7 @@
} \
}
MagickExport MagickPassFail HuffmanEncode2Image(const ImageInfo *image_info,
- Image *image, WriteByteHook write_byte, void *info)
+ Image *image, WriteByteHook \
write_byte, void *info) {
const HuffmanTable
*entry;
@@ -765,14 +765,19 @@
scanline=MagickAllocateMemory(unsigned char *,(size_t) width+1);
if (scanline == (unsigned char *) NULL)
ThrowBinaryException(ResourceLimitError,MemoryAllocationFailed,
- (char *) NULL);
+ (char *) NULL);
huffman_image=CloneImage(image,0,0,True,&image->exception);
if (huffman_image == (Image *) NULL)
{
MagickFreeMemory(scanline);
return(MagickFail);
}
- status &= SetImageType(huffman_image,BilevelType);
+ if (SetImageType(huffman_image,BilevelType) != MagickPass)
+ {
+ CopyException(&image->exception,&huffman_image->exception);
+ MagickFreeMemory(scanline);
+ return(MagickFail);
+ }
byte=0;
bit=0x80;
if (is_fax == True)
@@ -790,103 +795,107 @@
polarity=(PixelIntensity(&huffman_image->colormap[0]) < (MaxRGB/2));
if (huffman_image->colors == 2)
polarity=(PixelIntensityToQuantum(&huffman_image->colormap[0]) <
- PixelIntensityToQuantum(&huffman_image->colormap[1]) ? 0x00 : 0x01);
+ PixelIntensityToQuantum(&huffman_image->colormap[1]) ? 0x00 : 0x01);
q=scanline;
for (i=0; i < width; i++) /* was: for (i=(long) width; i > 0; i--) */
*q++=(unsigned char) polarity;
q=scanline;
for (y=0; y < huffman_image->rows; y++)
- {
- p=AcquireImagePixels(huffman_image,0,y,huffman_image->columns,1,
- &huffman_image->exception);
- if (p == (const PixelPacket *) NULL)
- {
- status=MagickFail;
- break;
- }
- indexes=AccessImmutableIndexes(huffman_image);
- for (x=0; x < huffman_image->columns; x++)
{
- *q=(unsigned char) (indexes[x] == polarity ? !polarity : polarity);
- q++;
- }
- /*
- Huffman encode scanline.
- */
- q=scanline;
- for (n=(long) width; n > 0; )
- {
+ p=AcquireImagePixels(huffman_image,0,y,huffman_image->columns,1,
+ &huffman_image->exception);
+ indexes=AccessImmutableIndexes(huffman_image);
+ if ((p == (const PixelPacket *) NULL) ||
+ (indexes == (const IndexPacket *) NULL))
+ {
+ status=MagickFail;
+ break;
+ }
+ for (x=0; x < huffman_image->columns; x++)
+ {
+ *q=(unsigned char) (indexes[x] == polarity ? !polarity : polarity);
+ q++;
+ }
/*
- Output white run.
+ Huffman encode scanline.
*/
- for (runlength=0; ((n > 0) && (*q == polarity)); n--)
- {
- q++;
- runlength++;
- }
- if (runlength >= 64)
- {
- if (runlength < 1792)
- entry=MWTable+(((size_t) runlength/64)-1);
- else
- entry=EXTable+(Min(runlength,2560)-1792)/64;
- runlength-=entry->count;
- HuffmanOutputCode(entry);
- }
- entry=TWTable+Min(runlength,63);
- HuffmanOutputCode(entry);
- if (n != 0)
+ q=scanline;
+ for (n=(long) width; n > 0; )
{
/*
- Output black run.
+ Output white run.
*/
- for (runlength=0; ((*q != polarity) && (n > 0)); n--)
- {
- q++;
- runlength++;
- }
+ for (runlength=0; ((n > 0) && (*q == polarity)); n--)
+ {
+ q++;
+ runlength++;
+ }
if (runlength >= 64)
{
- entry=MBTable+(((size_t) runlength/64)-1);
- if (runlength >= 1792)
+ if (runlength < 1792)
+ entry=MWTable+(((size_t) runlength/64)-1);
+ else
entry=EXTable+(Min(runlength,2560)-1792)/64;
runlength-=entry->count;
HuffmanOutputCode(entry);
}
- entry=TBTable+Min(runlength,63);
+ entry=TWTable+Min(runlength,63);
HuffmanOutputCode(entry);
+ if (n != 0)
+ {
+ /*
+ Output black run.
+ */
+ for (runlength=0; ((*q != polarity) && (n > 0)); n--)
+ {
+ q++;
+ runlength++;
+ }
+ if (runlength >= 64)
+ {
+ entry=MBTable+(((size_t) runlength/64)-1);
+ if (runlength >= 1792)
+ entry=EXTable+(Min(runlength,2560)-1792)/64;
+ runlength-=entry->count;
+ HuffmanOutputCode(entry);
+ }
+ entry=TBTable+Min(runlength,63);
+ HuffmanOutputCode(entry);
+ }
+ } /* for (n=... */
+ /*
+ End of line.
+ */
+ for (k=0; k < 11; k++)
+ OutputBit(0);
+ OutputBit(1);
+ q=scanline;
+ if (huffman_image->previous == (Image *) NULL)
+ if (QuantumTick(y,huffman_image->rows))
+ if (!MagickMonitorFormatted(y,huffman_image->rows,&image->exception,
+ "[%s] Huffman encode \
image...",image->filename)) + {
+ status=MagickFail;
+ break;
+ }
+ } /* for (y=... */
+ if (status == MagickPass)
+ {
+ /*
+ End of page.
+ */
+ for (i=0; i < 6; i++)
+ {
+ for (k=0; k < 11; k++)
+ OutputBit(0);
+ OutputBit(1);
}
+ /*
+ Flush bits.
+ */
+ if (bit != 0x80U)
+ (void) (*write_byte)(image,(magick_uint8_t)byte,info);
}
- /*
- End of line.
- */
- for (k=0; k < 11; k++)
- OutputBit(0);
- OutputBit(1);
- q=scanline;
- if (huffman_image->previous == (Image *) NULL)
- if (QuantumTick(y,huffman_image->rows))
- if (!MagickMonitorFormatted(y,huffman_image->rows,&image->exception,
- "[%s] Huffman encode image...",image->filename))
- {
- status=MagickFail;
- break;
- }
- }
- /*
- End of page.
- */
- for (i=0; i < 6; i++)
- {
- for (k=0; k < 11; k++)
- OutputBit(0);
- OutputBit(1);
- }
- /*
- Flush bits.
- */
- if (bit != 0x80U)
- (void) (*write_byte)(image,(magick_uint8_t)byte,info);
DestroyImage(huffman_image);
MagickFreeMemory(scanline);
return(status);
diff -r f226cbdadb83 -r b2b75f418d41 magick/decorate.c
--- a/magick/decorate.c Mon Dec 21 08:24:40 2020 -0600
+++ b/magick/decorate.c Mon Dec 21 19:41:29 2020 -0600
@@ -246,51 +246,54 @@
*/
height=(long) (frame_info->outer_bevel+(frame_info->y-bevel_width)+
frame_info->inner_bevel);
- q=SetImagePixelsEx(frame_image,0,0,frame_image->columns,height,exception);
- if (q != (PixelPacket *) NULL)
+ if (height > 0)
{
- for (y=0; y < frame_info->outer_bevel; y++)
+ q=SetImagePixelsEx(frame_image,0,0,frame_image->columns,height,exception);
+ if (q != (PixelPacket *) NULL)
{
- for (x=0; x < (long) (frame_image->columns-y); x++)
- if (x < y)
- *q++=highlight;
- else
- *q++=accentuate;
- for ( ; x < (long) frame_image->columns; x++)
- *q++=shadow;
- }
- for (y=0; y < (long) (frame_info->y-bevel_width); y++)
- {
- for (x=0; x < frame_info->outer_bevel; x++)
- *q++=highlight;
_______________________________________________
Graphicsmagick-commit mailing list
Graphicsmagick-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/graphicsmagick-commit
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic