GraphicsMagick: coders/xpm.c Allow to read pallete that contains...
GraphicsMagick Commits <[email protected]>
| Newsgroups | gmane.comp.video.graphicsmagick.cvs |
|---|---|
| Message-ID | <mailman.12533.1667430572.1350.graphicsmagick-commit@lists.sourceforge.net> |
changeset bedcaa9739b7 in /hg/GraphicsMagick details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=bedcaa9739b7 summary: coders/xpm.c Allow to read pallete that contains more colors than MaxColormapSize. diffstat: ChangeLog | 5 +++++ coders/xpm.c | 27 +++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diffs (71 lines): diff -r ed73da6ca2e7 -r bedcaa9739b7 ChangeLog --- a/ChangeLog Tue Nov 01 13:45:58 2022 -0500 +++ b/ChangeLog Thu Nov 03 00:08:58 2022 +0100 @@ -1,3 +1,8 @@ +2022-11-03 Fojtik Jaroslav <[email protected]> + + * coders/xpm.c Allow to read pallete that contains more colors + than MaxColormapSize. + 2022-11-01 Bob Friesenhahn <[email protected]> * magick/image.c (SetImageInfo): Avoid creating temporary files diff -r ed73da6ca2e7 -r bedcaa9739b7 coders/xpm.c --- a/coders/xpm.c Tue Nov 01 13:45:58 2022 -0500 +++ b/coders/xpm.c Thu Nov 03 00:08:58 2022 +0100 @@ -50,6 +50,8 @@ #include "magick/utility.h" +#define MAX_XPM_SUPPORTED_COLORS Max(0x20000,MaxColormapSize) + /* Forward declarations. */ @@ -373,9 +375,9 @@ (image->columns == 0) || (image->rows == 0) || (image->colors == 0)) ThrowXPMReaderException(CorruptImageError,ImproperImageHeader,image); - if (image->colors > MaxColormapSize) + if(image->colors > MAX_XPM_SUPPORTED_COLORS) ThrowXPMReaderException(CoderError,ColormapTooLarge,image); - image->depth=16; /* TODO: Depth 16 is nonsense in many cases, please fix. */ + image->depth=16; /* Remove unquoted characters. @@ -445,8 +447,19 @@ keys[i].index=0; keys[i].keyval=0; } - if (!AllocateImageColormap(image,image->colors)) - ThrowXPMReaderException(ResourceLimitError,MemoryAllocationFailed,image); + if(image->colors <= MaxColormapSize) + { + if (!AllocateImageColormap(image,image->colors)) + ThrowXPMReaderException(ResourceLimitError,MemoryAllocationFailed,image); + } + else /* Allocate temporary palette. */ + { + if(image->colormap != (PixelPacket *)NULL) + MagickFreeMemory(image->colormap); + image->colormap=MagickAllocateMemory(PixelPacket *,MagickArraySize((size_t) image->colors,sizeof(PixelPacket))); + if(image->colormap==NULL) + ThrowXPMReaderException(ResourceLimitError,MemoryAllocationFailed,image); + } /* Read image colormap. @@ -644,6 +657,12 @@ MagickFreeResourceLimitedMemory(keys); MagickFreeResourceLimitedMemory(textlist); MagickFreeResourceLimitedMemory(xpm_buffer); + if (image->colors > MaxColormapSize) + { /* Release temporary palette. */ + MagickFreeMemory(image->colormap); + image->colors = 0; + image->storage_class = DirectClass; + } CloseBlob(image); StopTimer(&image->timer); return(image);