#include "MagickCore/list.h"
#include "MagickCore/magick.h"
#include "MagickCore/memory_.h"
+#include "MagickCore/memory-private.h"
#include "MagickCore/module.h"
#include "MagickCore/monitor.h"
#include "MagickCore/monitor-private.h"
%
*/
+static void *AcquireCompressionMemory(void *context,
+ const size_t items,const size_t size)
+{
+ size_t
+ extent;
+
+ if (HeapOverflowSanityCheck(items,size) != MagickFalse)
+ return((void *) NULL);
+ extent=items*size;
+ /* Check if the buffer is big enough when we get a large request */
+ if (extent > 2000000)
+ {
+ Image
+ *image;
+
+ image=(Image *) context;
+ if ((MagickSizeType) extent > GetBlobSize(image))
+ return((void *) NULL);
+ }
+ return(AcquireMagickMemory(extent));
+}
+
#if defined(MAGICKCORE_BZLIB_DELEGATE)
static void *AcquireBZIPMemory(void *context,int items,int size)
{
- (void) context;
- return((void *) AcquireQuantumMemory((size_t) items,(size_t) size));
+ return(AcquireCompressionMemory(context,(size_t) items,(size_t) size));
}
#endif
#if defined(MAGICKCORE_LZMA_DELEGATE)
static void *AcquireLZMAMemory(void *context,size_t items,size_t size)
{
- (void) context;
- return((void *) AcquireQuantumMemory((size_t) items,(size_t) size));
+ return(AcquireCompressionMemory(context,items,size));
}
#endif
static voidpf AcquireZIPMemory(voidpf context,unsigned int items,
unsigned int size)
{
- (void) context;
- return((voidpf) AcquireQuantumMemory(items,size));
+ return((voidpf) AcquireCompressionMemory(context,(size_t) items,
+ (size_t) size));
}
#endif
bzip_info.bzalloc=AcquireBZIPMemory;
bzip_info.bzfree=RelinquishBZIPMemory;
- bzip_info.opaque=(void *) NULL;
+ bzip_info.opaque=(void *) image;
code=BZ2_bzDecompressInit(&bzip_info,(int) image_info->verbose,
MagickFalse);
if (code != BZ_OK)
allocator.alloc=AcquireLZMAMemory;
allocator.free=RelinquishLZMAMemory;
+ allocator.opaque=(void *) image;
lzma_info=initialize_lzma;
lzma_info.allocator=(&allocator);
code=lzma_auto_decoder(&lzma_info,-1,0);
zip_info.zalloc=AcquireZIPMemory;
zip_info.zfree=RelinquishZIPMemory;
- zip_info.opaque=(voidpf) NULL;
+ zip_info.opaque=(voidpf) image;
code=inflateInit(&zip_info);
if (code != Z_OK)
status=MagickFalse;