Changeset 7458 for ImageMagick/trunk/coders/png.c
- Timestamp:
- 04/12/12 10:16:21 (13 months ago)
- File:
-
- 1 edited
-
ImageMagick/trunk/coders/png.c (modified) (34 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ImageMagick/trunk/coders/png.c
r7219 r7458 585 585 #endif 586 586 587 #if defined(PNG_SETJMP_NOT_THREAD_SAFE)587 #ifdef PNG_SETJMP_NOT_THREAD_SAFE 588 588 static SemaphoreInfo 589 589 *ping_semaphore = (SemaphoreInfo *) NULL; … … 1809 1809 1810 1810 static int 1811 Magick_png_read_raw_profile( Image *image, const ImageInfo *image_info,1812 png_textp text,int ii,ExceptionInfo *exception)1811 Magick_png_read_raw_profile(png_struct *ping,Image *image, 1812 const ImageInfo *image_info, png_textp text,int ii,ExceptionInfo *exception) 1813 1813 { 1814 1814 register ssize_t … … 1856 1856 if (length == 0) 1857 1857 { 1858 (void) ThrowMagickException(exception,GetMagickModule(), 1859 CoderWarning,"UnableToCopyProfile","`%s'","invalid profile length"); 1858 png_warning(ping,"invalid profile length"); 1860 1859 return(MagickFalse); 1861 1860 } … … 1865 1864 if (profile == (StringInfo *) NULL) 1866 1865 { 1867 (void) ThrowMagickException(exception,GetMagickModule(), 1868 ResourceLimitError,"MemoryAllocationFailed","`%s'", 1869 "unable to copy profile"); 1866 png_warning(ping, "unable to copy profile"); 1870 1867 return(MagickFalse); 1871 1868 } … … 1881 1878 if (*sp == '\0') 1882 1879 { 1883 (void) ThrowMagickException(exception,GetMagickModule(), 1884 CoderWarning,"UnableToCopyProfile","`%s'","ran out of data"); 1880 png_warning(ping, "ran out of profile data"); 1885 1881 profile=DestroyStringInfo(profile); 1886 1882 return(MagickFalse); … … 2086 2082 logging=LogMagickEvent(CoderEvent,GetMagickModule(), 2087 2083 " Enter ReadOnePNGImage()"); 2088 2089 #if defined(PNG_SETJMP_NOT_THREAD_SAFE)2090 LockSemaphoreInfo(ping_semaphore);2091 #endif2092 2084 2093 2085 #if (PNG_LIBPNG_VER < 10200) … … 2166 2158 */ 2167 2159 png_destroy_read_struct(&ping,&ping_info,&end_info); 2168 #if defined(PNG_SETJMP_NOT_THREAD_SAFE) 2160 2161 #ifdef PNG_SETJMP_NOT_THREAD_SAFE 2169 2162 UnlockSemaphoreInfo(ping_semaphore); 2170 2163 #endif 2164 2165 if (ping_pixels != (unsigned char *) NULL) 2166 ping_pixels=(unsigned char *) RelinquishMagickMemory(ping_pixels); 2167 2171 2168 if (logging != MagickFalse) 2172 2169 (void) LogMagickEvent(CoderEvent,GetMagickModule(), … … 2181 2178 return(GetFirstImageInList(image)); 2182 2179 } 2180 2181 /* { For navigation to end of SETJMP-protected block. Within this 2182 * block, use png_error() instead of Throwing an Exception, to ensure 2183 * that libpng is able to clean up, and that the semaphore is unlocked. 2184 */ 2185 2186 #ifdef PNG_SETJMP_NOT_THREAD_SAFE 2187 LockSemaphoreInfo(ping_semaphore); 2188 #endif 2189 2183 2190 /* 2184 2191 Prepare PNG for reading. … … 2315 2322 profile=BlobToStringInfo(info,profile_length); 2316 2323 if (profile == (StringInfo *) NULL) 2317 {2318 (void) ThrowMagickException(exception,GetMagickModule(),2319 ResourceLimitError,"MemoryAllocationFailed","`%s'",2320 "unable to copy profile");2321 return((Image *) NULL);2322 }2323 SetStringInfoDatum(profile,(const unsigned char *) info);2324 (void) SetImageProfile(image,"icc",profile,exception);2325 profile=DestroyStringInfo(profile);2324 { 2325 png_warning(ping, "ICC profile is NULL"); 2326 profile=DestroyStringInfo(profile); 2327 } 2328 else 2329 { 2330 (void) SetImageProfile(image,"icc",profile,exception); 2331 profile=DestroyStringInfo(profile); 2332 } 2326 2333 } 2327 2334 } … … 2470 2477 2471 2478 if (!png_get_valid(ping,ping_info,PNG_INFO_tRNS)) 2479 { 2472 2480 if (mng_info->global_trns_length) 2473 2481 { 2474 if (mng_info->global_trns_length > 2475 mng_info->global_plte_length) 2476 (void) ThrowMagickException(exception, 2477 GetMagickModule(),CoderError, 2478 "global tRNS has more entries than global PLTE", 2479 "`%s'",image_info->filename); 2480 png_set_tRNS(ping,ping_info,mng_info->global_trns, 2481 (int) mng_info->global_trns_length,NULL); 2482 png_warning(ping, 2483 "global tRNS has more entries than global PLTE"); 2482 2484 } 2485 else 2486 { 2487 png_set_tRNS(ping,ping_info,mng_info->global_trns, 2488 (int) mng_info->global_trns_length,NULL); 2489 } 2490 } 2483 2491 #ifdef PNG_READ_bKGD_SUPPORTED 2484 2492 if ( … … 2515 2523 } 2516 2524 else 2517 (void) ThrowMagickException(exception,GetMagickModule(), 2518 CoderError,"No global PLTE in file","`%s'", 2519 image_info->filename); 2525 png_error(ping,"No global PLTE in file"); 2520 2526 } 2521 2527 } … … 2732 2738 */ 2733 2739 if (AcquireImageColormap(image,image->colors,exception) == MagickFalse) 2734 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");2740 png_error(ping,"Memory allocation failed"); 2735 2741 2736 2742 if ((int) ping_color_type == PNG_COLOR_TYPE_PALETTE) … … 2820 2826 mng_info->scenes_found-1); 2821 2827 png_destroy_read_struct(&ping,&ping_info,&end_info); 2822 #if defined(PNG_SETJMP_NOT_THREAD_SAFE) 2828 2829 #ifdef PNG_SETJMP_NOT_THREAD_SAFE 2823 2830 UnlockSemaphoreInfo(ping_semaphore); 2824 2831 #endif 2832 2825 2833 if (logging != MagickFalse) 2826 2834 (void) LogMagickEvent(CoderEvent,GetMagickModule(), … … 2843 2851 2844 2852 if (ping_pixels == (unsigned char *) NULL) 2845 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");2853 png_error(ping,"Memory allocation failed"); 2846 2854 2847 2855 if (logging != MagickFalse) … … 2851 2859 Convert PNG pixels to pixel packets. 2852 2860 */ 2853 if (setjmp(png_jmpbuf(ping)))2854 {2855 /*2856 PNG image is corrupt.2857 */2858 png_destroy_read_struct(&ping,&ping_info,&end_info);2859 #if defined(PNG_SETJMP_NOT_THREAD_SAFE)2860 UnlockSemaphoreInfo(ping_semaphore);2861 #endif2862 if (quantum_info != (QuantumInfo *) NULL)2863 quantum_info = DestroyQuantumInfo(quantum_info);2864 2865 if (ping_pixels != (unsigned char *) NULL)2866 ping_pixels=(unsigned char *) RelinquishMagickMemory(ping_pixels);2867 2868 if (logging != MagickFalse)2869 (void) LogMagickEvent(CoderEvent,GetMagickModule(),2870 " exit ReadOnePNGImage() with error.");2871 2872 if (image != (Image *) NULL)2873 {2874 InheritException(exception,exception);2875 image->columns=0;2876 }2877 2878 return(GetFirstImageInList(image));2879 }2880 2881 2861 quantum_info=AcquireQuantumInfo(image_info,image); 2882 2862 2883 2863 if (quantum_info == (QuantumInfo *) NULL) 2884 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");2864 png_error(ping,"Failed to allocate quantum_info"); 2885 2865 2886 2866 { … … 3027 3007 3028 3008 if (quantum_scanline == (Quantum *) NULL) 3029 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");3009 png_error(ping,"Memory allocation failed"); 3030 3010 3031 3011 for (y=0; y < (ssize_t) image->rows; y++) … … 3254 3234 image->colors=2; 3255 3235 (void) SetImageBackgroundColor(image,exception); 3256 #if defined(PNG_SETJMP_NOT_THREAD_SAFE)3236 #ifdef PNG_SETJMP_NOT_THREAD_SAFE 3257 3237 UnlockSemaphoreInfo(ping_semaphore); 3258 3238 #endif … … 3371 3351 if (memcmp(text[i].key, "Raw profile type ",17) == 0) 3372 3352 { 3373 (void) Magick_png_read_raw_profile( image,image_info,text,(int) i,3374 exception);3353 (void) Magick_png_read_raw_profile(ping,image,image_info,text, 3354 (int) i,exception); 3375 3355 num_raw_profiles++; 3376 3356 } … … 3386 3366 if (value == (char *) NULL) 3387 3367 { 3388 (void) ThrowMagickException(exception,GetMagickModule(), 3389 ResourceLimitError,"MemoryAllocationFailed","`%s'", 3390 image->filename); 3368 png_error(ping,"Memory allocation failed"); 3391 3369 break; 3392 3370 } … … 3441 3419 { 3442 3420 if (mng_info->ob[object_id] == (MngBuffer *) NULL) 3443 (void) ThrowMagickException(exception,GetMagickModule(), 3444 ResourceLimitError,"MemoryAllocationFailed","`%s'", 3445 image->filename); 3421 png_error(ping,"Memory allocation failed"); 3446 3422 3447 3423 if (mng_info->ob[object_id]->frozen) 3448 (void) ThrowMagickException(exception,GetMagickModule(), 3449 ResourceLimitError,"Cannot overwrite frozen MNG object buffer", 3450 "`%s'",image->filename); 3424 png_error(ping,"Cannot overwrite frozen MNG object buffer"); 3451 3425 } 3452 3426 … … 3465 3439 3466 3440 else 3467 (void) ThrowMagickException(exception,GetMagickModule(), 3468 ResourceLimitError,"Cloning image for object buffer failed", 3469 "`%s'",image->filename); 3441 png_error(ping, "Cloning image for object buffer failed"); 3470 3442 3471 3443 if (ping_width > 250000L || ping_height > 250000L) … … 3622 3594 3623 3595 ping_pixels=(unsigned char *) RelinquishMagickMemory(ping_pixels); 3624 #if defined(PNG_SETJMP_NOT_THREAD_SAFE)3625 UnlockSemaphoreInfo(ping_semaphore);3626 #endif3627 3596 3628 3597 if (logging != MagickFalse) 3629 3598 (void) LogMagickEvent(CoderEvent,GetMagickModule(), 3630 3599 " exit ReadOnePNGImage()"); 3600 3601 #ifdef PNG_SETJMP_NOT_THREAD_SAFE 3602 UnlockSemaphoreInfo(ping_semaphore); 3603 #endif 3604 3605 /* } for navigation to beginning of SETJMP-protected block, revert to 3606 * Throwing an Exception when an error occurs. 3607 */ 3631 3608 3632 3609 return(image); … … 4994 4971 { 4995 4972 /* 4996 Instead of suing a warning we should allocate a larger4973 Instead of using a warning we should allocate a larger 4997 4974 MngInfo structure and continue. 4998 4975 */ … … 7208 7185 (void) RegisterMagickInfo(entry); 7209 7186 7210 #if defined(PNG_SETJMP_NOT_THREAD_SAFE)7187 #ifdef PNG_SETJMP_NOT_THREAD_SAFE 7211 7188 ping_semaphore=AllocateSemaphoreInfo(); 7212 7189 #endif … … 7243 7220 (void) UnregisterMagickInfo("JNG"); 7244 7221 7245 #if defined(PNG_SETJMP_NOT_THREAD_SAFE)7222 #ifdef PNG_SETJMP_NOT_THREAD_SAFE 7246 7223 if (ping_semaphore != (SemaphoreInfo *) NULL) 7247 7224 DestroySemaphoreInfo(&ping_semaphore); … … 7592 7569 if (image_info == (ImageInfo *) NULL) 7593 7570 ThrowWriterException(ResourceLimitError, "MemoryAllocationFailed"); 7594 7595 #if defined(PNG_SETJMP_NOT_THREAD_SAFE)7596 LockSemaphoreInfo(ping_semaphore);7597 #endif7598 7571 7599 7572 /* Initialize some stuff */ … … 8875 8848 "Cannot write PNG8 or color-type 3; colormap is NULL", 8876 8849 "`%s'",IMimage->filename); 8877 #if defined(PNG_SETJMP_NOT_THREAD_SAFE)8878 UnlockSemaphoreInfo(ping_semaphore);8879 #endif8880 8850 return(MagickFalse); 8881 8851 } … … 8920 8890 #endif 8921 8891 png_destroy_write_struct(&ping,&ping_info); 8922 #if defined(PNG_SETJMP_NOT_THREAD_SAFE)8892 #ifdef PNG_SETJMP_NOT_THREAD_SAFE 8923 8893 UnlockSemaphoreInfo(ping_semaphore); 8924 8894 #endif 8895 8896 if (ping_pixels != (unsigned char *) NULL) 8897 ping_pixels=(unsigned char *) RelinquishMagickMemory(ping_pixels); 8898 8899 if (quantum_info != (QuantumInfo *) NULL) 8900 quantum_info=DestroyQuantumInfo(quantum_info); 8901 8925 8902 if (ping_have_blob != MagickFalse) 8926 8903 (void) CloseBlob(image); … … 8929 8906 return(MagickFalse); 8930 8907 } 8908 8909 /* { For navigation to end of SETJMP-protected block. Within this 8910 * block, use png_error() instead of Throwing an Exception, to ensure 8911 * that libpng is able to clean up, and that the semaphore is unlocked. 8912 */ 8913 8914 #ifdef PNG_SETJMP_NOT_THREAD_SAFE 8915 LockSemaphoreInfo(ping_semaphore); 8916 #endif 8917 8931 8918 /* 8932 8919 Prepare PNG for writing. … … 9283 9270 { 9284 9271 /* DO SOMETHING */ 9285 (void) ThrowMagickException(exception, 9286 GetMagickModule(),CoderError, 9287 "image has 0 colors", "`%s'",""); 9272 png_error(ping,"image has 0 colors"); 9288 9273 } 9289 9274 … … 10311 10296 10312 10297 if (ping_pixels == (unsigned char *) NULL) 10313 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");10298 png_error(ping,"Allocation of memory for pixels failed"); 10314 10299 10315 10300 /* 10316 10301 Initialize image scanlines. 10317 10302 */ 10318 if (setjmp(png_jmpbuf(ping)))10319 {10320 /*10321 PNG write failed.10322 */10323 #ifdef PNG_DEBUG10324 if (image_info->verbose)10325 (void) printf("PNG write has failed.\n");10326 #endif10327 png_destroy_write_struct(&ping,&ping_info);10328 if (quantum_info != (QuantumInfo *) NULL)10329 quantum_info=DestroyQuantumInfo(quantum_info);10330 if (ping_pixels != (unsigned char *) NULL)10331 ping_pixels=(unsigned char *) RelinquishMagickMemory(ping_pixels);10332 #if defined(PNG_SETJMP_NOT_THREAD_SAFE)10333 UnlockSemaphoreInfo(ping_semaphore);10334 #endif10335 if (ping_have_blob != MagickFalse)10336 (void) CloseBlob(image);10337 image_info=DestroyImageInfo(image_info);10338 image=DestroyImage(image);10339 return(MagickFalse);10340 }10341 10303 quantum_info=AcquireQuantumInfo(image_info,image); 10342 10304 if (quantum_info == (QuantumInfo *) NULL) 10343 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");10305 png_error(ping,"Memory allocation for quantum_info failed"); 10344 10306 quantum_info->format=UndefinedQuantumFormat; 10345 10307 quantum_info->depth=image_depth; … … 10757 10719 if (mng_info->write_mng && !mng_info->need_fram && 10758 10720 ((int) image->dispose == 3)) 10759 (void) ThrowMagickException(exception,GetMagickModule(), 10760 CoderError,"Cannot convert GIF with disposal method 3 to MNG-LC", 10761 "`%s'",image->filename); 10721 png_error(ping, "Cannot convert GIF with disposal method 3 to MNG-LC"); 10762 10722 10763 10723 /* … … 10769 10729 ping_pixels=(unsigned char *) RelinquishMagickMemory(ping_pixels); 10770 10730 10771 #if defined(PNG_SETJMP_NOT_THREAD_SAFE)10772 UnlockSemaphoreInfo(ping_semaphore);10773 #endif10774 10775 10731 if (ping_have_blob != MagickFalse) 10776 10732 (void) CloseBlob(image); … … 10789 10745 " exit WriteOnePNGImage()"); 10790 10746 10747 #ifdef PNG_SETJMP_NOT_THREAD_SAFE 10748 UnlockSemaphoreInfo(ping_semaphore); 10749 #endif 10750 10751 /* } for navigation to beginning of SETJMP-protected block. Revert to 10752 * Throwing an Exception when an error occurs. 10753 */ 10754 10791 10755 return(MagickTrue); 10792 10756 /* End write one PNG image */ 10757 10793 10758 } 10794 10759
Note: See TracChangeset
for help on using the changeset viewer.
