#define PNG_SETJMP_NOT_THREAD_SAFE
#endif
-#if defined(PNG_SETJMP_NOT_THREAD_SAFE)
+#ifdef PNG_SETJMP_NOT_THREAD_SAFE
static SemaphoreInfo
*ping_semaphore = (SemaphoreInfo *) NULL;
#endif
#endif
static int
-Magick_png_read_raw_profile(Image *image, const ImageInfo *image_info,
- png_textp text,int ii,ExceptionInfo *exception)
+Magick_png_read_raw_profile(png_struct *ping,Image *image,
+ const ImageInfo *image_info, png_textp text,int ii,ExceptionInfo *exception)
{
register ssize_t
i;
/* allocate space */
if (length == 0)
{
- (void) ThrowMagickException(exception,GetMagickModule(),
- CoderWarning,"UnableToCopyProfile","`%s'","invalid profile length");
+ png_warning(ping,"invalid profile length");
return(MagickFalse);
}
if (profile == (StringInfo *) NULL)
{
- (void) ThrowMagickException(exception,GetMagickModule(),
- ResourceLimitError,"MemoryAllocationFailed","`%s'",
- "unable to copy profile");
+ png_warning(ping, "unable to copy profile");
return(MagickFalse);
}
{
if (*sp == '\0')
{
- (void) ThrowMagickException(exception,GetMagickModule(),
- CoderWarning,"UnableToCopyProfile","`%s'","ran out of data");
+ png_warning(ping, "ran out of profile data");
profile=DestroyStringInfo(profile);
return(MagickFalse);
}
logging=LogMagickEvent(CoderEvent,GetMagickModule(),
" Enter ReadOnePNGImage()");
-#if defined(PNG_SETJMP_NOT_THREAD_SAFE)
- LockSemaphoreInfo(ping_semaphore);
-#endif
-
#if (PNG_LIBPNG_VER < 10200)
if (image_info->verbose)
printf("Your PNG library (libpng-%s) is rather old.\n",
PNG image is corrupt.
*/
png_destroy_read_struct(&ping,&ping_info,&end_info);
-#if defined(PNG_SETJMP_NOT_THREAD_SAFE)
+
+#ifdef PNG_SETJMP_NOT_THREAD_SAFE
UnlockSemaphoreInfo(ping_semaphore);
#endif
+
+ if (ping_pixels != (unsigned char *) NULL)
+ ping_pixels=(unsigned char *) RelinquishMagickMemory(ping_pixels);
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" exit ReadOnePNGImage() with error.");
return(GetFirstImageInList(image));
}
+
+ /* { For navigation to end of SETJMP-protected block. Within this
+ * block, use png_error() instead of Throwing an Exception, to ensure
+ * that libpng is able to clean up, and that the semaphore is unlocked.
+ */
+
+#ifdef PNG_SETJMP_NOT_THREAD_SAFE
+ LockSemaphoreInfo(ping_semaphore);
+#endif
+
/*
Prepare PNG for reading.
*/
" Reading PNG iCCP chunk.");
profile=BlobToStringInfo(info,profile_length);
if (profile == (StringInfo *) NULL)
- {
- (void) ThrowMagickException(exception,GetMagickModule(),
- ResourceLimitError,"MemoryAllocationFailed","`%s'",
- "unable to copy profile");
- return((Image *) NULL);
- }
- SetStringInfoDatum(profile,(const unsigned char *) info);
- (void) SetImageProfile(image,"icc",profile,exception);
- profile=DestroyStringInfo(profile);
+ {
+ png_warning(ping, "ICC profile is NULL");
+ profile=DestroyStringInfo(profile);
+ }
+ else
+ {
+ (void) SetImageProfile(image,"icc",profile,exception);
+ profile=DestroyStringInfo(profile);
+ }
}
}
#endif
(int) mng_info->global_plte_length);
if (!png_get_valid(ping,ping_info,PNG_INFO_tRNS))
+ {
if (mng_info->global_trns_length)
{
- if (mng_info->global_trns_length >
- mng_info->global_plte_length)
- (void) ThrowMagickException(exception,
- GetMagickModule(),CoderError,
- "global tRNS has more entries than global PLTE",
- "`%s'",image_info->filename);
- png_set_tRNS(ping,ping_info,mng_info->global_trns,
- (int) mng_info->global_trns_length,NULL);
+ png_warning(ping,
+ "global tRNS has more entries than global PLTE");
}
+ else
+ {
+ png_set_tRNS(ping,ping_info,mng_info->global_trns,
+ (int) mng_info->global_trns_length,NULL);
+ }
+ }
#ifdef PNG_READ_bKGD_SUPPORTED
if (
#ifndef PNG_READ_EMPTY_PLTE_SUPPORTED
#endif
}
else
- (void) ThrowMagickException(exception,GetMagickModule(),
- CoderError,"No global PLTE in file","`%s'",
- image_info->filename);
+ png_error(ping,"No global PLTE in file");
}
}
Initialize image colormap.
*/
if (AcquireImageColormap(image,image->colors,exception) == MagickFalse)
- ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+ png_error(ping,"Memory allocation failed");
if ((int) ping_color_type == PNG_COLOR_TYPE_PALETTE)
{
" Skipping PNG image data for scene %.20g",(double)
mng_info->scenes_found-1);
png_destroy_read_struct(&ping,&ping_info,&end_info);
-#if defined(PNG_SETJMP_NOT_THREAD_SAFE)
+
+#ifdef PNG_SETJMP_NOT_THREAD_SAFE
UnlockSemaphoreInfo(ping_semaphore);
#endif
+
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" exit ReadOnePNGImage().");
sizeof(*ping_pixels));
if (ping_pixels == (unsigned char *) NULL)
- ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+ png_error(ping,"Memory allocation failed");
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
/*
Convert PNG pixels to pixel packets.
*/
- if (setjmp(png_jmpbuf(ping)))
- {
- /*
- PNG image is corrupt.
- */
- png_destroy_read_struct(&ping,&ping_info,&end_info);
-#if defined(PNG_SETJMP_NOT_THREAD_SAFE)
- UnlockSemaphoreInfo(ping_semaphore);
-#endif
- if (quantum_info != (QuantumInfo *) NULL)
- quantum_info = DestroyQuantumInfo(quantum_info);
-
- if (ping_pixels != (unsigned char *) NULL)
- ping_pixels=(unsigned char *) RelinquishMagickMemory(ping_pixels);
-
- if (logging != MagickFalse)
- (void) LogMagickEvent(CoderEvent,GetMagickModule(),
- " exit ReadOnePNGImage() with error.");
-
- if (image != (Image *) NULL)
- {
- InheritException(exception,exception);
- image->columns=0;
- }
-
- return(GetFirstImageInList(image));
- }
-
quantum_info=AcquireQuantumInfo(image_info,image);
if (quantum_info == (QuantumInfo *) NULL)
- ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+ png_error(ping,"Failed to allocate quantum_info");
{
(image->matte ? 2 : 1)*sizeof(*quantum_scanline));
if (quantum_scanline == (Quantum *) NULL)
- ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+ png_error(ping,"Memory allocation failed");
for (y=0; y < (ssize_t) image->rows; y++)
{
ping_pixels=(unsigned char *) RelinquishMagickMemory(ping_pixels);
image->colors=2;
(void) SetImageBackgroundColor(image,exception);
-#if defined(PNG_SETJMP_NOT_THREAD_SAFE)
+#ifdef PNG_SETJMP_NOT_THREAD_SAFE
UnlockSemaphoreInfo(ping_semaphore);
#endif
if (logging != MagickFalse)
if (memcmp(text[i].key, "Raw profile type ",17) == 0)
{
- (void) Magick_png_read_raw_profile(image,image_info,text,(int) i,
- exception);
+ (void) Magick_png_read_raw_profile(ping,image,image_info,text,
+ (int) i,exception);
num_raw_profiles++;
}
sizeof(*value));
if (value == (char *) NULL)
{
- (void) ThrowMagickException(exception,GetMagickModule(),
- ResourceLimitError,"MemoryAllocationFailed","`%s'",
- image->filename);
+ png_error(ping,"Memory allocation failed");
break;
}
*value='\0';
mng_info->ob[object_id]->frozen)
{
if (mng_info->ob[object_id] == (MngBuffer *) NULL)
- (void) ThrowMagickException(exception,GetMagickModule(),
- ResourceLimitError,"MemoryAllocationFailed","`%s'",
- image->filename);
+ png_error(ping,"Memory allocation failed");
if (mng_info->ob[object_id]->frozen)
- (void) ThrowMagickException(exception,GetMagickModule(),
- ResourceLimitError,"Cannot overwrite frozen MNG object buffer",
- "`%s'",image->filename);
+ png_error(ping,"Cannot overwrite frozen MNG object buffer");
}
else
mng_info->ob[object_id]->image->file=(FILE *) NULL;
else
- (void) ThrowMagickException(exception,GetMagickModule(),
- ResourceLimitError,"Cloning image for object buffer failed",
- "`%s'",image->filename);
+ png_error(ping, "Cloning image for object buffer failed");
if (ping_width > 250000L || ping_height > 250000L)
png_error(ping,"PNG Image dimensions are too large.");
png_destroy_read_struct(&ping,&ping_info,&end_info);
ping_pixels=(unsigned char *) RelinquishMagickMemory(ping_pixels);
-#if defined(PNG_SETJMP_NOT_THREAD_SAFE)
- UnlockSemaphoreInfo(ping_semaphore);
-#endif
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" exit ReadOnePNGImage()");
+#ifdef PNG_SETJMP_NOT_THREAD_SAFE
+ UnlockSemaphoreInfo(ping_semaphore);
+#endif
+
+ /* } for navigation to beginning of SETJMP-protected block, revert to
+ * Throwing an Exception when an error occurs.
+ */
+
return(image);
/* end of reading one PNG image */
if (object_id > MNG_MAX_OBJECTS)
{
/*
- Instead ofsuing a warning we should allocate a larger
+ Instead of using a warning we should allocate a larger
MngInfo structure and continue.
*/
(void) ThrowMagickException(exception,GetMagickModule(),
entry->note=ConstantString(JNGNote);
(void) RegisterMagickInfo(entry);
-#if defined(PNG_SETJMP_NOT_THREAD_SAFE)
+#ifdef PNG_SETJMP_NOT_THREAD_SAFE
ping_semaphore=AllocateSemaphoreInfo();
#endif
(void) UnregisterMagickInfo("PNG32");
(void) UnregisterMagickInfo("JNG");
-#if defined(PNG_SETJMP_NOT_THREAD_SAFE)
+#ifdef PNG_SETJMP_NOT_THREAD_SAFE
if (ping_semaphore != (SemaphoreInfo *) NULL)
DestroySemaphoreInfo(&ping_semaphore);
#endif
if (image_info == (ImageInfo *) NULL)
ThrowWriterException(ResourceLimitError, "MemoryAllocationFailed");
-#if defined(PNG_SETJMP_NOT_THREAD_SAFE)
- LockSemaphoreInfo(ping_semaphore);
-#endif
-
/* Initialize some stuff */
ping_bit_depth=0,
ping_color_type=0,
(void) ThrowMagickException(exception,GetMagickModule(),CoderError,
"Cannot write PNG8 or color-type 3; colormap is NULL",
"`%s'",IMimage->filename);
-#if defined(PNG_SETJMP_NOT_THREAD_SAFE)
- UnlockSemaphoreInfo(ping_semaphore);
-#endif
return(MagickFalse);
}
(void) printf("PNG write has failed.\n");
#endif
png_destroy_write_struct(&ping,&ping_info);
-#if defined(PNG_SETJMP_NOT_THREAD_SAFE)
+#ifdef PNG_SETJMP_NOT_THREAD_SAFE
UnlockSemaphoreInfo(ping_semaphore);
#endif
+
+ if (ping_pixels != (unsigned char *) NULL)
+ ping_pixels=(unsigned char *) RelinquishMagickMemory(ping_pixels);
+
+ if (quantum_info != (QuantumInfo *) NULL)
+ quantum_info=DestroyQuantumInfo(quantum_info);
+
if (ping_have_blob != MagickFalse)
(void) CloseBlob(image);
image_info=DestroyImageInfo(image_info);
image=DestroyImage(image);
return(MagickFalse);
}
+
+ /* { For navigation to end of SETJMP-protected block. Within this
+ * block, use png_error() instead of Throwing an Exception, to ensure
+ * that libpng is able to clean up, and that the semaphore is unlocked.
+ */
+
+#ifdef PNG_SETJMP_NOT_THREAD_SAFE
+ LockSemaphoreInfo(ping_semaphore);
+#endif
+
/*
Prepare PNG for writing.
*/
if (image->colors == 0)
{
/* DO SOMETHING */
- (void) ThrowMagickException(exception,
- GetMagickModule(),CoderError,
- "image has 0 colors", "`%s'","");
+ png_error(ping,"image has 0 colors");
}
while ((int) (one << ping_bit_depth) < (ssize_t) image_colors)
sizeof(*ping_pixels));
if (ping_pixels == (unsigned char *) NULL)
- ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
+ png_error(ping,"Allocation of memory for pixels failed");
/*
Initialize image scanlines.
*/
- if (setjmp(png_jmpbuf(ping)))
- {
- /*
- PNG write failed.
- */
-#ifdef PNG_DEBUG
- if (image_info->verbose)
- (void) printf("PNG write has failed.\n");
-#endif
- png_destroy_write_struct(&ping,&ping_info);
- if (quantum_info != (QuantumInfo *) NULL)
- quantum_info=DestroyQuantumInfo(quantum_info);
- if (ping_pixels != (unsigned char *) NULL)
- ping_pixels=(unsigned char *) RelinquishMagickMemory(ping_pixels);
-#if defined(PNG_SETJMP_NOT_THREAD_SAFE)
- UnlockSemaphoreInfo(ping_semaphore);
-#endif
- if (ping_have_blob != MagickFalse)
- (void) CloseBlob(image);
- image_info=DestroyImageInfo(image_info);
- image=DestroyImage(image);
- return(MagickFalse);
- }
quantum_info=AcquireQuantumInfo(image_info,image);
if (quantum_info == (QuantumInfo *) NULL)
- ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
+ png_error(ping,"Memory allocation for quantum_info failed");
quantum_info->format=UndefinedQuantumFormat;
quantum_info->depth=image_depth;
num_passes=png_set_interlace_handling(ping);
}
if (mng_info->write_mng && !mng_info->need_fram &&
((int) image->dispose == 3))
- (void) ThrowMagickException(exception,GetMagickModule(),
- CoderError,"Cannot convert GIF with disposal method 3 to MNG-LC",
- "`%s'",image->filename);
+ png_error(ping, "Cannot convert GIF with disposal method 3 to MNG-LC");
/*
Free PNG resources.
ping_pixels=(unsigned char *) RelinquishMagickMemory(ping_pixels);
-#if defined(PNG_SETJMP_NOT_THREAD_SAFE)
- UnlockSemaphoreInfo(ping_semaphore);
-#endif
-
if (ping_have_blob != MagickFalse)
(void) CloseBlob(image);
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" exit WriteOnePNGImage()");
+#ifdef PNG_SETJMP_NOT_THREAD_SAFE
+ UnlockSemaphoreInfo(ping_semaphore);
+#endif
+
+ /* } for navigation to beginning of SETJMP-protected block. Revert to
+ * Throwing an Exception when an error occurs.
+ */
+
return(MagickTrue);
/* End write one PNG image */
+
}
/*