#if !defined(MAP_FAILED)
#define MAP_FAILED ((void *) -1)
#endif
+#if !defined(MS_SYNC)
+#define MS_SYNC 0x04
+#endif
#if defined(__OS2__)
#include <io.h>
#define _O_BINARY O_BINARY
extent,
quantum;
- MapMode
- mode;
-
MagickBooleanType
mapped,
eof;
return;
(void) CloseBlob(image);
if (image->blob->mapped != MagickFalse)
- (void) UnmapBlob(image->blob->data,image->blob->length);
+ {
+ (void) UnmapBlob(image->blob->data,image->blob->length);
+ RelinquishMagickResource(MapResource,image->blob->length);
+ }
if (image->blob->semaphore != (SemaphoreInfo *) NULL)
DestroySemaphoreInfo(&image->blob->semaphore);
image->blob->signature=(~MagickSignature);
if (blob_info->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
if (blob_info->mapped != MagickFalse)
- (void) UnmapBlob(blob_info->data,blob_info->length);
+ {
+ (void) UnmapBlob(blob_info->data,blob_info->length);
+ RelinquishMagickResource(MapResource,blob_info->length);
+ }
blob_info->mapped=MagickFalse;
blob_info->length=0;
blob_info->offset=0;
ExceptionInfo
*sans_exception;
+ size_t
+ length;
+
struct stat
*properties;
magick_info=GetMagickInfo(image_info->magick,sans_exception);
sans_exception=DestroyExceptionInfo(sans_exception);
properties=(&image->blob->properties);
+ length=(size_t) properties->st_size;
if ((magick_info != (const MagickInfo *) NULL) &&
(GetMagickBlobSupport(magick_info) != MagickFalse) &&
- (properties->st_size <= MagickMaxBufferExtent))
+ (AcquireMagickResource(MapResource,length) != MagickFalse))
{
- size_t
- length;
-
void
*blob;
- length=(size_t) properties->st_size;
blob=MapBlob(fileno(image->blob->file_info.file),ReadMode,
0,length);
- if (blob != (void *) NULL)
+ if (blob == (void *) NULL)
+ RelinquishMagickResource(MapResource,length);
+ else
{
/*
Format supports blobs-- use memory-mapped I/O.
}
AttachBlob(image->blob,blob,length);
image->blob->mapped=MagickTrue;
- image->blob->mode=ReadMode;
}
}
}
count;
(void) UnmapBlob(image->blob->data,image->blob->length);
+ RelinquishMagickResource(MapResource,image->blob->length);
if (extent != (MagickSizeType) ((off_t) extent))
return(MagickFalse);
offset=SeekBlob(image,0,SEEK_END);
image->blob->file_info.file),WriteMode,0,(size_t) extent);
image->blob->extent=(size_t) extent;
image->blob->length=(size_t) extent;
- image->blob->mode=WriteMode;
+ (void) AcquireMagickResource(MapResource,extent);
(void) SyncBlob(image);
break;
}
break;
case BlobStream:
{
-#if defined(MAGICKCORE_HAVE_MMAP_FILEIO) && defined(MS_SYNC)
- if ((image->blob->mapped != MagickFalse) &&
- ((image->blob->mode == WriteMode) || (image->blob->mode == IOMode)))
+#if defined(MAGICKCORE_HAVE_MMAP_FILEIO)
+ if (image->blob->mapped != MagickFalse)
status=msync(image->blob->data,image->blob->length,MS_SYNC);
#endif
break;
*image;
MagickBooleanType
+ mapped,
status;
MagickOffsetType
bmp_info.bits_per_pixel<<=1;
bytes_per_line=4*((image->columns*bmp_info.bits_per_pixel+31)/32);
length=(size_t) bytes_per_line*image->rows;
- pixels=(unsigned char *) AcquireQuantumMemory((size_t) image->rows,
- MagickMax(bytes_per_line,image->columns+256UL)*sizeof(*pixels));
- if (pixels == (unsigned char *) NULL)
- ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+ mapped=MagickFalse;
if ((bmp_info.compression == BI_RGB) ||
(bmp_info.compression == BI_BITFIELDS))
{
if (image->debug != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Reading pixels (%.20g bytes)",(double) length);
- count=ReadBlob(image,length,pixels);
- if (count != (ssize_t) length)
+ if (GetBlobStreamData(image) != (unsigned char *) NULL)
{
- pixels=(unsigned char *) RelinquishMagickMemory(pixels);
- ThrowReaderException(CorruptImageError,
- "InsufficientImageDataInFile");
+ mapped=MagickTrue;
+ pixels=GetBlobStreamData(image)+TellBlob(image);
+ if (DiscardBlobBytes(image,length) == MagickFalse)
+ ThrowReaderException(CorruptImageError,
+ "InsufficientImageDataInFile");
+ }
+ else
+ {
+ pixels=(unsigned char *) AcquireQuantumMemory((size_t) image->rows,
+ MagickMax(bytes_per_line,image->columns)*sizeof(*pixels));
+ if (pixels == (unsigned char *) NULL)
+ ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+ count=ReadBlob(image,length,pixels);
+ if (count != (ssize_t) length)
+ {
+ pixels=(unsigned char *) RelinquishMagickMemory(pixels);
+ ThrowReaderException(CorruptImageError,
+ "InsufficientImageDataInFile");
+ }
}
}
else
/*
Convert run-length encoded raster pixels.
*/
+ pixels=(unsigned char *) AcquireQuantumMemory((size_t) image->rows,
+ MagickMax(bytes_per_line,image->columns+256UL)*sizeof(*pixels));
+ if (pixels == (unsigned char *) NULL)
+ ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
status=DecodeImage(image,bmp_info.compression,pixels);
if (status == MagickFalse)
{
if (bmp_info.compression != BI_RGB &&
bmp_info.compression != BI_BITFIELDS)
{
- pixels=(unsigned char *) RelinquishMagickMemory(pixels);
+ if (mapped == MagickFalse)
+ pixels=(unsigned char *) RelinquishMagickMemory(pixels);
ThrowReaderException(CorruptImageError,
"UnrecognizedImageCompression");
}
if ((bmp_info.compression != BI_RGB) &&
(bmp_info.compression != BI_BITFIELDS))
{
- pixels=(unsigned char *) RelinquishMagickMemory(pixels);
+ if (mapped == MagickFalse)
+ pixels=(unsigned char *) RelinquishMagickMemory(pixels);
ThrowReaderException(CorruptImageError,
"UnrecognizedImageCompression");
}
}
default:
{
- pixels=(unsigned char *) RelinquishMagickMemory(pixels);
+ if (mapped == MagickFalse)
+ pixels=(unsigned char *) RelinquishMagickMemory(pixels);
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
}
}
- pixels=(unsigned char *) RelinquishMagickMemory(pixels);
+ if (mapped == MagickFalse)
+ pixels=(unsigned char *) RelinquishMagickMemory(pixels);
if (EOFBlob(image) != MagickFalse)
{
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",