]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/blob.c
(no commit message)
[imagemagick] / MagickCore / blob.c
index 876a66f11c1a94d83179658ad82252456efb4811..cbcae1bd5063ffeb1e453b86999f59a78472d9ef 100644 (file)
@@ -355,10 +355,10 @@ MagickExport Image *BlobToImage(const ImageInfo *image_info,const void *blob,
   magick_info=GetMagickInfo(blob_info->magick,exception);
   if (magick_info == (const MagickInfo *) NULL)
     {
-      blob_info=DestroyImageInfo(blob_info);
       (void) ThrowMagickException(exception,GetMagickModule(),
         MissingDelegateError,"NoDecodeDelegateForThisImageFormat","`%s'",
-        image_info->filename);
+        blob_info->magick);
+      blob_info=DestroyImageInfo(blob_info);
       return((Image *) NULL);
     }
   if (GetMagickBlobSupport(magick_info) != MagickFalse)
@@ -399,14 +399,16 @@ MagickExport Image *BlobToImage(const ImageInfo *image_info,const void *blob,
         *images;
 
       /*
-        Restore original filenames.
+        Restore original filenames and image format.
       */
       for (images=GetFirstImageInList(image); images != (Image *) NULL; )
       {
-        (void) CopyMagickMemory(images->filename,image_info->filename,
-          sizeof(images->filename));
-        (void) CopyMagickMemory(images->magick_filename,image_info->filename,
-          sizeof(images->magick_filename));
+        (void) CopyMagickString(images->filename,image_info->filename,
+          MaxTextExtent);
+        (void) CopyMagickString(images->magick_filename,image_info->filename,
+          MaxTextExtent);
+        (void) CopyMagickString(images->magick,magick_info->name,
+          MaxTextExtent);
         images=GetNextImageInList(images);
       }
     }
@@ -690,6 +692,7 @@ MagickExport unsigned char *DetachBlob(BlobInfo *blob_info)
   if (blob_info->mapped != MagickFalse)
     {
       (void) UnmapBlob(blob_info->data,blob_info->length);
+      blob_info->data=(unsigned char *) NULL;
       RelinquishMagickResource(MapResource,blob_info->length);
     }
   blob_info->mapped=MagickFalse;
@@ -1162,6 +1165,7 @@ MagickExport MagickBooleanType FileToImage(Image *image,const char *filename,
   blob=(unsigned char *) AcquireQuantumMemory(quantum,sizeof(*blob));
   if (blob == (unsigned char *) NULL)
     {
+      file=close(file);
       ThrowFileException(exception,ResourceLimitError,"MemoryAllocationFailed",
         filename);
       return(MagickFalse);
@@ -1525,7 +1529,8 @@ MagickExport unsigned char *ImageToBlob(const ImageInfo *image_info,
     {
       (void) ThrowMagickException(exception,GetMagickModule(),
         MissingDelegateError,"NoDecodeDelegateForThisImageFormat","`%s'",
-        image->filename);
+        image->magick);
+      blob_info=DestroyImageInfo(blob_info);
       return(blob);
     }
   (void) CopyMagickString(blob_info->magick,image->magick,MaxTextExtent);
@@ -1580,6 +1585,8 @@ MagickExport unsigned char *ImageToBlob(const ImageInfo *image_info,
               (void) FormatLocaleString(image->filename,MaxTextExtent,"%s:%s",
                 image->magick,unique);
               status=WriteImage(blob_info,image,exception);
+              (void) CloseBlob(image);
+              (void) fclose(blob_info->file);
               if (status != MagickFalse)
                 blob=FileToBlob(unique,~0UL,length,exception);
             }
@@ -1697,6 +1704,8 @@ MagickExport MagickBooleanType ImageToFile(Image *image,char *filename,
   buffer=(unsigned char *) RelinquishMagickMemory(buffer);
   if ((file == -1) || (i < length))
     {
+      if (file != -1)
+        file=close(file);
       ThrowFileException(exception,BlobError,"UnableToWriteBlob",filename);
       return(MagickFalse);
     }
@@ -1773,7 +1782,8 @@ MagickExport unsigned char *ImagesToBlob(const ImageInfo *image_info,
     {
       (void) ThrowMagickException(exception,GetMagickModule(),
         MissingDelegateError,"NoDecodeDelegateForThisImageFormat","`%s'",
-        images->filename);
+        images->magick);
+      blob_info=DestroyImageInfo(blob_info);
       return(blob);
     }
   if (GetMagickAdjoin(magick_info) == MagickFalse)
@@ -1833,9 +1843,8 @@ MagickExport unsigned char *ImagesToBlob(const ImageInfo *image_info,
             {
               (void) FormatLocaleString(filename,MaxTextExtent,"%s:%s",
                 images->magick,unique);
-              images->blob->exempt=MagickTrue;
-              *images->filename='\0';
               status=WriteImages(blob_info,images,filename,exception);
+              (void) CloseBlob(images);
               (void) fclose(blob_info->file);
               if (status != MagickFalse)
                 blob=FileToBlob(unique,~0UL,length,exception);
@@ -2533,7 +2542,9 @@ MagickExport MagickBooleanType OpenBlob(const ImageInfo *image_info,
             if (((int) magick[0] == 0x1F) && ((int) magick[1] == 0x8B) &&
                 ((int) magick[2] == 0x08))
               {
-                (void) fclose(image->blob->file_info.file);
+                if (image->blob->file_info.file != (FILE *) NULL)
+                  (void) fclose(image->blob->file_info.file);
+                image->blob->file_info.file=(FILE *) NULL;
                 image->blob->file_info.gzfile=gzopen(filename,type);
                 if (image->blob->file_info.gzfile != (gzFile) NULL)
                   image->blob->type=ZipStream;
@@ -2542,7 +2553,9 @@ MagickExport MagickBooleanType OpenBlob(const ImageInfo *image_info,
 #if defined(MAGICKCORE_BZLIB_DELEGATE)
             if (strncmp((char *) magick,"BZh",3) == 0)
               {
-                (void) fclose(image->blob->file_info.file);
+                if (image->blob->file_info.file != (FILE *) NULL)
+                  (void) fclose(image->blob->file_info.file);
+                image->blob->file_info.file=(FILE *) NULL;
                 image->blob->file_info.bzfile=BZ2_bzopen(filename,type);
                 if (image->blob->file_info.bzfile != (BZFILE *) NULL)
                   image->blob->type=BZipStream;
@@ -3589,6 +3602,8 @@ MagickExport MagickOffsetType SeekBlob(Image *image,
       return(-1);
     case FileStream:
     {
+      if ((whence == SEEK_SET) && (offset < 0))
+        return(-1);
       if (fseek(image->blob->file_info.file,offset,whence) < 0)
         return(-1);
       image->blob->offset=TellBlob(image);