@@ -75,9 +75,6 @@ static void php_free_ps_enc(zend_rsrc_list_entry *rsrc TSRMLS_DC);
7575#include <gdfontl.h> /* 4 Large font */
7676#include <gdfontg.h> /* 5 Giant font */
7777
78- #ifdef HAVE_GD_WBMP
79- #include "libgd/wbmp.h"
80- #endif
8178#ifdef ENABLE_GD_TTF
8279# ifdef HAVE_LIBFREETYPE
8380# include <ft2build.h>
@@ -241,7 +238,7 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagesavealpha, 0)
241238 ZEND_ARG_INFO (0 , save )
242239ZEND_END_ARG_INFO ()
243240
244- #if HAVE_GD_BUNDLED
241+ #if defined( HAVE_GD_BUNDLED ) || defined( HAVE_LIBGD21 )
245242ZEND_BEGIN_ARG_INFO (arginfo_imagelayereffect , 0 )
246243 ZEND_ARG_INFO (0 , im )
247244 ZEND_ARG_INFO (0 , effect )
@@ -368,7 +365,7 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromxbm, 0)
368365ZEND_END_ARG_INFO ()
369366#endif
370367
371- #if defined(HAVE_GD_XPM ) && defined(HAVE_GD_BUNDLED )
368+ #if defined(HAVE_GD_XPM ) && ( defined(HAVE_GD_BUNDLED ) || defined( HAVE_LIBGD21 ) )
372369ZEND_BEGIN_ARG_INFO (arginfo_imagecreatefromxpm , 0 )
373370 ZEND_ARG_INFO (0 , filename )
374371ZEND_END_ARG_INFO ()
@@ -398,7 +395,7 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromgd2part, 0)
398395ZEND_END_ARG_INFO ()
399396#endif
400397
401- #if HAVE_GD_BUNDLED
398+ #if defined( HAVE_GD_BUNDLED ) || defined( HAVE_LIBGD21 )
402399ZEND_BEGIN_ARG_INFO_EX (arginfo_imagexbm , 0 , 0 , 2 )
403400 ZEND_ARG_INFO (0 , im )
404401 ZEND_ARG_INFO (0 , filename )
@@ -897,7 +894,9 @@ ZEND_BEGIN_ARG_INFO(arginfo_imageantialias, 0)
897894 ZEND_ARG_INFO (0 , im )
898895 ZEND_ARG_INFO (0 , on )
899896ZEND_END_ARG_INFO ()
897+ #endif
900898
899+ #if defined(HAVE_GD_BUNDLED ) || defined(HAVE_LIBGD21 )
901900ZEND_BEGIN_ARG_INFO (arginfo_imagecrop , 0 )
902901 ZEND_ARG_INFO (0 , im )
903902 ZEND_ARG_INFO (0 , rect )
@@ -1002,6 +1001,8 @@ const zend_function_entry gd_functions[] = {
10021001
10031002#ifdef HAVE_GD_BUNDLED
10041003 PHP_FE (imageantialias , arginfo_imageantialias )
1004+ #endif
1005+ #if defined(HAVE_GD_BUNDLED ) || defined (HAVE_LIBGD21 )
10051006 PHP_FE (imagecrop , arginfo_imagecrop )
10061007 PHP_FE (imagecropauto , arginfo_imagecropauto )
10071008 PHP_FE (imagescale , arginfo_imagescale )
@@ -1039,7 +1040,7 @@ const zend_function_entry gd_functions[] = {
10391040#ifdef HAVE_GD_XBM
10401041 PHP_FE (imagecreatefromxbm , arginfo_imagecreatefromxbm )
10411042#endif
1042- #if defined(HAVE_GD_XPM ) && defined (HAVE_GD_BUNDLED )
1043+ #if defined(HAVE_GD_XPM ) && ( defined (HAVE_GD_BUNDLED ) || defined ( HAVE_LIBGD21 ) )
10431044 PHP_FE (imagecreatefromxpm , arginfo_imagecreatefromxpm )
10441045#endif
10451046 PHP_FE (imagecreatefromgd , arginfo_imagecreatefromgd )
@@ -1119,7 +1120,7 @@ const zend_function_entry gd_functions[] = {
11191120#ifdef HAVE_GD_WBMP
11201121 PHP_FE (image2wbmp , arginfo_image2wbmp )
11211122#endif
1122- #if HAVE_GD_BUNDLED
1123+ #if defined( HAVE_GD_BUNDLED ) || defined ( HAVE_LIBGD21 )
11231124 PHP_FE (imagelayereffect , arginfo_imagelayereffect )
11241125 PHP_FE (imagexbm , arginfo_imagexbm )
11251126#endif
@@ -1187,6 +1188,18 @@ static void php_free_gd_font(zend_rsrc_list_entry *rsrc TSRMLS_DC)
11871188}
11881189/* }}} */
11891190
1191+ #ifdef HAVE_LIBGD21
1192+ /* {{{ php_gd_error_method
1193+ */
1194+ void php_gd_error_method (int type , const char * format , va_list args )
1195+ {
1196+ TSRMLS_FETCH ();
1197+
1198+ php_verror (NULL , "" , type , format , args TSRMLS_CC );
1199+ }
1200+ /* }}} */
1201+ #endif
1202+
11901203/* {{{ PHP_MSHUTDOWN_FUNCTION
11911204 */
11921205#if HAVE_LIBT1 || HAVE_GD_FONTMUTEX
@@ -1222,7 +1235,9 @@ PHP_MINIT_FUNCTION(gd)
12221235 le_ps_font = zend_register_list_destructors_ex (php_free_ps_font , NULL , "gd PS font" , module_number );
12231236 le_ps_enc = zend_register_list_destructors_ex (php_free_ps_enc , NULL , "gd PS encoding" , module_number );
12241237#endif
1225-
1238+ #ifdef HAVE_LIBGD21
1239+ gdSetErrorMethod (php_gd_error_method );
1240+ #endif
12261241 REGISTER_INI_ENTRIES ();
12271242
12281243 REGISTER_LONG_CONSTANT ("IMG_GIF" , 1 , CONST_CS | CONST_PERSISTENT );
@@ -1258,7 +1273,7 @@ PHP_MINIT_FUNCTION(gd)
12581273 REGISTER_LONG_CONSTANT ("IMG_FLIP_VERTICAL" , GD_FLIP_VERTICAL , CONST_CS | CONST_PERSISTENT );
12591274 REGISTER_LONG_CONSTANT ("IMG_FLIP_BOTH" , GD_FLIP_BOTH , CONST_CS | CONST_PERSISTENT );
12601275#endif
1261- #if HAVE_GD_BUNDLED
1276+ #if defined( HAVE_GD_BUNDLED ) || defined( HAVE_LIBGD21 )
12621277 REGISTER_LONG_CONSTANT ("IMG_EFFECT_REPLACE" , gdEffectReplace , CONST_CS | CONST_PERSISTENT );
12631278 REGISTER_LONG_CONSTANT ("IMG_EFFECT_ALPHABLEND" , gdEffectAlphaBlend , CONST_CS | CONST_PERSISTENT );
12641279 REGISTER_LONG_CONSTANT ("IMG_EFFECT_NORMAL" , gdEffectNormal , CONST_CS | CONST_PERSISTENT );
@@ -1367,7 +1382,7 @@ PHP_RSHUTDOWN_FUNCTION(gd)
13671382#endif
13681383/* }}} */
13691384
1370- #if HAVE_GD_BUNDLED
1385+ #if defined( HAVE_GD_BUNDLED )
13711386#define PHP_GD_VERSION_STRING "bundled (2.1.0 compatible)"
13721387#else
13731388# ifdef GD_VERSION_STRING
@@ -1413,8 +1428,6 @@ PHP_MINFO_FUNCTION(gd)
14131428 php_info_print_table_row (2 , "T1Lib Support" , "enabled" );
14141429#endif
14151430
1416- /* this next part is stupid ... if I knew better, I'd put them all on one row (cmv) */
1417-
14181431#ifdef HAVE_GD_GIF_READ
14191432 php_info_print_table_row (2 , "GIF Read Support" , "enabled" );
14201433#endif
@@ -1423,21 +1436,18 @@ PHP_MINFO_FUNCTION(gd)
14231436#endif
14241437#ifdef HAVE_GD_JPG
14251438 {
1426- char tmp [12 ];
1427- snprintf (tmp , sizeof (tmp ), "%s" , gdJpegGetVersionString ());
14281439 php_info_print_table_row (2 , "JPEG Support" , "enabled" );
1429- php_info_print_table_row (2 , "libJPEG Version" , tmp );
1440+ php_info_print_table_row (2 , "libJPEG Version" , gdJpegGetVersionString () );
14301441 }
14311442#endif
1432-
14331443#ifdef HAVE_GD_PNG
14341444 php_info_print_table_row (2 , "PNG Support" , "enabled" );
14351445 php_info_print_table_row (2 , "libPNG Version" , gdPngGetVersionString ());
14361446#endif
14371447#ifdef HAVE_GD_WBMP
14381448 php_info_print_table_row (2 , "WBMP Support" , "enabled" );
14391449#endif
1440- #if defined(HAVE_GD_XPM ) && defined(HAVE_GD_BUNDLED )
1450+ #if defined(HAVE_GD_XPM ) && ( defined(HAVE_GD_BUNDLED ) || defined( HAVE_LIBGD21 ) )
14411451 php_info_print_table_row (2 , "XPM Support" , "enabled" );
14421452 {
14431453 char tmp [12 ];
@@ -1448,7 +1458,7 @@ PHP_MINFO_FUNCTION(gd)
14481458#ifdef HAVE_GD_XBM
14491459 php_info_print_table_row (2 , "XBM Support" , "enabled" );
14501460#endif
1451- #if defined(USE_GD_JISX0208 ) && defined(HAVE_GD_BUNDLED )
1461+ #if defined(USE_GD_JISX0208 ) && ( defined(HAVE_GD_BUNDLED ) || defined( HAVE_LIBGD21 ) )
14521462 php_info_print_table_row (2 , "JIS-mapped Japanese Font Support" , "enabled" );
14531463#endif
14541464#ifdef HAVE_GD_WEBP
@@ -1512,7 +1522,7 @@ PHP_FUNCTION(gd_info)
15121522#else
15131523 add_assoc_bool (return_value , "WBMP Support" , 0 );
15141524#endif
1515- #if defined(HAVE_GD_XPM ) && defined(HAVE_GD_BUNDLED )
1525+ #if defined(HAVE_GD_XPM ) && ( defined(HAVE_GD_BUNDLED ) || defined( HAVE_LIBGD21 ) )
15161526 add_assoc_bool (return_value , "XPM Support" , 1 );
15171527#else
15181528 add_assoc_bool (return_value , "XPM Support" , 0 );
@@ -1522,7 +1532,7 @@ PHP_FUNCTION(gd_info)
15221532#else
15231533 add_assoc_bool (return_value , "XBM Support" , 0 );
15241534#endif
1525- #if defined(USE_GD_JISX0208 ) && defined(HAVE_GD_BUNDLED )
1535+ #if defined(USE_GD_JISX0208 ) && ( defined(HAVE_GD_BUNDLED ) || defined( HAVE_LIBGD21 ) )
15261536 add_assoc_bool (return_value , "JIS-mapped Japanese Font Support" , 1 );
15271537#else
15281538 add_assoc_bool (return_value , "JIS-mapped Japanese Font Support" , 0 );
@@ -1655,13 +1665,9 @@ PHP_FUNCTION(imageloadfont)
16551665 body_size = font -> w * font -> h * font -> nchars ;
16561666 }
16571667
1658- if (overflow2 (font -> nchars , font -> h )) {
1659- php_error_docref (NULL TSRMLS_CC , E_WARNING , "Error reading font, invalid font header" );
1660- efree (font );
1661- php_stream_close (stream );
1662- RETURN_FALSE ;
1663- }
1664- if (overflow2 (font -> nchars * font -> h , font -> w )) {
1668+ if ((font -> nchars <= 0 || font -> h <= 0 || font -> w <= 0 ) || \
1669+ (font -> nchars > INT_MAX / font -> h ) || \
1670+ (font -> nchars * font -> h > INT_MAX / font -> w )) {
16651671 php_error_docref (NULL TSRMLS_CC , E_WARNING , "Error reading font, invalid font header" );
16661672 efree (font );
16671673 php_stream_close (stream );
@@ -1984,7 +1990,7 @@ PHP_FUNCTION(imagesavealpha)
19841990}
19851991/* }}} */
19861992
1987- #if HAVE_GD_BUNDLED
1993+ #if defined( HAVE_GD_BUNDLED ) || defined( HAVE_LIBGD21 )
19881994/* {{{ proto bool imagelayereffect(resource im, int effect)
19891995 Set the alpha blending flag to use the bundled libgd layering effects */
19901996PHP_FUNCTION (imagelayereffect )
@@ -2375,7 +2381,7 @@ PHP_FUNCTION(imagetypes)
23752381#ifdef HAVE_GD_WBMP
23762382 ret |= 8 ;
23772383#endif
2378- #if defined(HAVE_GD_XPM ) && defined(HAVE_GD_BUNDLED )
2384+ #if defined(HAVE_GD_XPM ) && ( defined(HAVE_GD_BUNDLED ) || defined( HAVE_LIBGD21 ) )
23792385 ret |= 16 ;
23802386#endif
23812387
@@ -2387,6 +2393,23 @@ PHP_FUNCTION(imagetypes)
23872393}
23882394/* }}} */
23892395
2396+ /* {{{ _php_ctx_getmbi
2397+ */
2398+
2399+ static _php_ctx_getmbi (gdIOCtx * ctx )
2400+ {
2401+ int i , mbi = 0 ;
2402+
2403+ do {
2404+ i = (ctx -> getC )(ctx );
2405+ if (i < 0 ) {
2406+ break ;
2407+ }
2408+ mbi = (mbi << 7 ) | (i & 0x7f );
2409+ } while (i & 0x80 );
2410+ }
2411+ /* }}} */
2412+
23902413/* {{{ _php_image_type
23912414 */
23922415static const char php_sig_gd2 [3 ] = {'g' , 'd' , '2' };
@@ -2416,7 +2439,7 @@ static int _php_image_type (char data[8])
24162439 gdIOCtx * io_ctx ;
24172440 io_ctx = gdNewDynamicCtxEx (8 , data , 0 );
24182441 if (io_ctx ) {
2419- if (getmbi (( int ( * )( void * )) io_ctx -> getC , io_ctx ) == 0 && skipheader (( int ( * )( void * )) io_ctx -> getC , io_ctx ) == 0 ) {
2442+ if (_php_ctx_getmbi ( io_ctx ) == 0 && _php_ctx_getmbi ( io_ctx ) >= 0 ) {
24202443#if HAVE_LIBGD204
24212444 io_ctx -> gd_free (io_ctx );
24222445#else
@@ -2662,7 +2685,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
26622685 case PHP_GDIMG_TYPE_GD2PART :
26632686 im = (* func_p )(fp , srcx , srcy , width , height );
26642687 break ;
2665- #if defined(HAVE_GD_XPM ) && defined(HAVE_GD_BUNDLED )
2688+ #if defined(HAVE_GD_XPM ) && ( defined(HAVE_GD_BUNDLED ) || defined( HAVE_LIBGD21 ) )
26662689 case PHP_GDIMG_TYPE_XPM :
26672690 im = gdImageCreateFromXpm (file );
26682691 break ;
@@ -2752,7 +2775,7 @@ PHP_FUNCTION(imagecreatefromxbm)
27522775/* }}} */
27532776#endif /* HAVE_GD_XBM */
27542777
2755- #if defined(HAVE_GD_XPM ) && defined(HAVE_GD_BUNDLED )
2778+ #if defined(HAVE_GD_XPM ) && ( defined(HAVE_GD_BUNDLED ) || defined( HAVE_LIBGD21 ) )
27562779/* {{{ proto resource imagecreatefromxpm(string filename)
27572780 Create a new image from XPM file or URL */
27582781PHP_FUNCTION (imagecreatefromxpm )
@@ -2960,7 +2983,7 @@ static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char
29602983
29612984/* {{{ proto int imagexbm(int im, string filename [, int foreground])
29622985 Output XBM image to browser or file */
2963- #if HAVE_GD_BUNDLED
2986+ #if defined( HAVE_GD_BUNDLED ) || defined( HAVE_LIBGD21 )
29642987PHP_FUNCTION (imagexbm )
29652988{
29662989 _php_image_output_ctx (INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_XBM , "XBM" , gdImageXbmCtx );
@@ -5253,8 +5276,10 @@ PHP_FUNCTION(imageantialias)
52535276 RETURN_TRUE ;
52545277}
52555278/* }}} */
5279+ #endif
52565280
52575281
5282+ #if defined(HAVE_GD_BUNDLED ) || defined(HAVE_LIBGD21 )
52585283/* {{{ proto void imagecrop(resource im, array rect)
52595284 Crop an image using the given coordinates and size, x, y, width and height. */
52605285PHP_FUNCTION (imagecrop )
0 commit comments