@@ -75,9 +75,6 @@ static void php_free_ps_enc(zend_rsrc_list_entry *rsrc TSRMLS_DC);
75
75
#include <gdfontl.h> /* 4 Large font */
76
76
#include <gdfontg.h> /* 5 Giant font */
77
77
78
- #ifdef HAVE_GD_WBMP
79
- #include "libgd/wbmp.h"
80
- #endif
81
78
#ifdef ENABLE_GD_TTF
82
79
# ifdef HAVE_LIBFREETYPE
83
80
# include <ft2build.h>
@@ -241,7 +238,7 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagesavealpha, 0)
241
238
ZEND_ARG_INFO (0 , save )
242
239
ZEND_END_ARG_INFO ()
243
240
244
- #if HAVE_GD_BUNDLED
241
+ #if defined( HAVE_GD_BUNDLED ) || defined( HAVE_LIBGD21 )
245
242
ZEND_BEGIN_ARG_INFO (arginfo_imagelayereffect , 0 )
246
243
ZEND_ARG_INFO (0 , im )
247
244
ZEND_ARG_INFO (0 , effect )
@@ -368,7 +365,7 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromxbm, 0)
368
365
ZEND_END_ARG_INFO ()
369
366
#endif
370
367
371
- #if defined(HAVE_GD_XPM ) && defined(HAVE_GD_BUNDLED )
368
+ #if defined(HAVE_GD_XPM ) && ( defined(HAVE_GD_BUNDLED ) || defined( HAVE_LIBGD21 ) )
372
369
ZEND_BEGIN_ARG_INFO (arginfo_imagecreatefromxpm , 0 )
373
370
ZEND_ARG_INFO (0 , filename )
374
371
ZEND_END_ARG_INFO ()
@@ -398,7 +395,7 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromgd2part, 0)
398
395
ZEND_END_ARG_INFO ()
399
396
#endif
400
397
401
- #if HAVE_GD_BUNDLED
398
+ #if defined( HAVE_GD_BUNDLED ) || defined( HAVE_LIBGD21 )
402
399
ZEND_BEGIN_ARG_INFO_EX (arginfo_imagexbm , 0 , 0 , 2 )
403
400
ZEND_ARG_INFO (0 , im )
404
401
ZEND_ARG_INFO (0 , filename )
@@ -897,7 +894,9 @@ ZEND_BEGIN_ARG_INFO(arginfo_imageantialias, 0)
897
894
ZEND_ARG_INFO (0 , im )
898
895
ZEND_ARG_INFO (0 , on )
899
896
ZEND_END_ARG_INFO ()
897
+ #endif
900
898
899
+ #if defined(HAVE_GD_BUNDLED ) || defined(HAVE_LIBGD21 )
901
900
ZEND_BEGIN_ARG_INFO (arginfo_imagecrop , 0 )
902
901
ZEND_ARG_INFO (0 , im )
903
902
ZEND_ARG_INFO (0 , rect )
@@ -1002,6 +1001,8 @@ const zend_function_entry gd_functions[] = {
1002
1001
1003
1002
#ifdef HAVE_GD_BUNDLED
1004
1003
PHP_FE (imageantialias , arginfo_imageantialias )
1004
+ #endif
1005
+ #if defined(HAVE_GD_BUNDLED ) || defined (HAVE_LIBGD21 )
1005
1006
PHP_FE (imagecrop , arginfo_imagecrop )
1006
1007
PHP_FE (imagecropauto , arginfo_imagecropauto )
1007
1008
PHP_FE (imagescale , arginfo_imagescale )
@@ -1039,7 +1040,7 @@ const zend_function_entry gd_functions[] = {
1039
1040
#ifdef HAVE_GD_XBM
1040
1041
PHP_FE (imagecreatefromxbm , arginfo_imagecreatefromxbm )
1041
1042
#endif
1042
- #if defined(HAVE_GD_XPM ) && defined (HAVE_GD_BUNDLED )
1043
+ #if defined(HAVE_GD_XPM ) && ( defined (HAVE_GD_BUNDLED ) || defined ( HAVE_LIBGD21 ) )
1043
1044
PHP_FE (imagecreatefromxpm , arginfo_imagecreatefromxpm )
1044
1045
#endif
1045
1046
PHP_FE (imagecreatefromgd , arginfo_imagecreatefromgd )
@@ -1119,7 +1120,7 @@ const zend_function_entry gd_functions[] = {
1119
1120
#ifdef HAVE_GD_WBMP
1120
1121
PHP_FE (image2wbmp , arginfo_image2wbmp )
1121
1122
#endif
1122
- #if HAVE_GD_BUNDLED
1123
+ #if defined( HAVE_GD_BUNDLED ) || defined ( HAVE_LIBGD21 )
1123
1124
PHP_FE (imagelayereffect , arginfo_imagelayereffect )
1124
1125
PHP_FE (imagexbm , arginfo_imagexbm )
1125
1126
#endif
@@ -1187,6 +1188,18 @@ static void php_free_gd_font(zend_rsrc_list_entry *rsrc TSRMLS_DC)
1187
1188
}
1188
1189
/* }}} */
1189
1190
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
+
1190
1203
/* {{{ PHP_MSHUTDOWN_FUNCTION
1191
1204
*/
1192
1205
#if HAVE_LIBT1 || HAVE_GD_FONTMUTEX
@@ -1222,7 +1235,9 @@ PHP_MINIT_FUNCTION(gd)
1222
1235
le_ps_font = zend_register_list_destructors_ex (php_free_ps_font , NULL , "gd PS font" , module_number );
1223
1236
le_ps_enc = zend_register_list_destructors_ex (php_free_ps_enc , NULL , "gd PS encoding" , module_number );
1224
1237
#endif
1225
-
1238
+ #ifdef HAVE_LIBGD21
1239
+ gdSetErrorMethod (php_gd_error_method );
1240
+ #endif
1226
1241
REGISTER_INI_ENTRIES ();
1227
1242
1228
1243
REGISTER_LONG_CONSTANT ("IMG_GIF" , 1 , CONST_CS | CONST_PERSISTENT );
@@ -1258,7 +1273,7 @@ PHP_MINIT_FUNCTION(gd)
1258
1273
REGISTER_LONG_CONSTANT ("IMG_FLIP_VERTICAL" , GD_FLIP_VERTICAL , CONST_CS | CONST_PERSISTENT );
1259
1274
REGISTER_LONG_CONSTANT ("IMG_FLIP_BOTH" , GD_FLIP_BOTH , CONST_CS | CONST_PERSISTENT );
1260
1275
#endif
1261
- #if HAVE_GD_BUNDLED
1276
+ #if defined( HAVE_GD_BUNDLED ) || defined( HAVE_LIBGD21 )
1262
1277
REGISTER_LONG_CONSTANT ("IMG_EFFECT_REPLACE" , gdEffectReplace , CONST_CS | CONST_PERSISTENT );
1263
1278
REGISTER_LONG_CONSTANT ("IMG_EFFECT_ALPHABLEND" , gdEffectAlphaBlend , CONST_CS | CONST_PERSISTENT );
1264
1279
REGISTER_LONG_CONSTANT ("IMG_EFFECT_NORMAL" , gdEffectNormal , CONST_CS | CONST_PERSISTENT );
@@ -1367,7 +1382,7 @@ PHP_RSHUTDOWN_FUNCTION(gd)
1367
1382
#endif
1368
1383
/* }}} */
1369
1384
1370
- #if HAVE_GD_BUNDLED
1385
+ #if defined( HAVE_GD_BUNDLED )
1371
1386
#define PHP_GD_VERSION_STRING "bundled (2.1.0 compatible)"
1372
1387
#else
1373
1388
# ifdef GD_VERSION_STRING
@@ -1413,8 +1428,6 @@ PHP_MINFO_FUNCTION(gd)
1413
1428
php_info_print_table_row (2 , "T1Lib Support" , "enabled" );
1414
1429
#endif
1415
1430
1416
- /* this next part is stupid ... if I knew better, I'd put them all on one row (cmv) */
1417
-
1418
1431
#ifdef HAVE_GD_GIF_READ
1419
1432
php_info_print_table_row (2 , "GIF Read Support" , "enabled" );
1420
1433
#endif
@@ -1423,21 +1436,18 @@ PHP_MINFO_FUNCTION(gd)
1423
1436
#endif
1424
1437
#ifdef HAVE_GD_JPG
1425
1438
{
1426
- char tmp [12 ];
1427
- snprintf (tmp , sizeof (tmp ), "%s" , gdJpegGetVersionString ());
1428
1439
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 () );
1430
1441
}
1431
1442
#endif
1432
-
1433
1443
#ifdef HAVE_GD_PNG
1434
1444
php_info_print_table_row (2 , "PNG Support" , "enabled" );
1435
1445
php_info_print_table_row (2 , "libPNG Version" , gdPngGetVersionString ());
1436
1446
#endif
1437
1447
#ifdef HAVE_GD_WBMP
1438
1448
php_info_print_table_row (2 , "WBMP Support" , "enabled" );
1439
1449
#endif
1440
- #if defined(HAVE_GD_XPM ) && defined(HAVE_GD_BUNDLED )
1450
+ #if defined(HAVE_GD_XPM ) && ( defined(HAVE_GD_BUNDLED ) || defined( HAVE_LIBGD21 ) )
1441
1451
php_info_print_table_row (2 , "XPM Support" , "enabled" );
1442
1452
{
1443
1453
char tmp [12 ];
@@ -1448,7 +1458,7 @@ PHP_MINFO_FUNCTION(gd)
1448
1458
#ifdef HAVE_GD_XBM
1449
1459
php_info_print_table_row (2 , "XBM Support" , "enabled" );
1450
1460
#endif
1451
- #if defined(USE_GD_JISX0208 ) && defined(HAVE_GD_BUNDLED )
1461
+ #if defined(USE_GD_JISX0208 ) && ( defined(HAVE_GD_BUNDLED ) || defined( HAVE_LIBGD21 ) )
1452
1462
php_info_print_table_row (2 , "JIS-mapped Japanese Font Support" , "enabled" );
1453
1463
#endif
1454
1464
#ifdef HAVE_GD_WEBP
@@ -1512,7 +1522,7 @@ PHP_FUNCTION(gd_info)
1512
1522
#else
1513
1523
add_assoc_bool (return_value , "WBMP Support" , 0 );
1514
1524
#endif
1515
- #if defined(HAVE_GD_XPM ) && defined(HAVE_GD_BUNDLED )
1525
+ #if defined(HAVE_GD_XPM ) && ( defined(HAVE_GD_BUNDLED ) || defined( HAVE_LIBGD21 ) )
1516
1526
add_assoc_bool (return_value , "XPM Support" , 1 );
1517
1527
#else
1518
1528
add_assoc_bool (return_value , "XPM Support" , 0 );
@@ -1522,7 +1532,7 @@ PHP_FUNCTION(gd_info)
1522
1532
#else
1523
1533
add_assoc_bool (return_value , "XBM Support" , 0 );
1524
1534
#endif
1525
- #if defined(USE_GD_JISX0208 ) && defined(HAVE_GD_BUNDLED )
1535
+ #if defined(USE_GD_JISX0208 ) && ( defined(HAVE_GD_BUNDLED ) || defined( HAVE_LIBGD21 ) )
1526
1536
add_assoc_bool (return_value , "JIS-mapped Japanese Font Support" , 1 );
1527
1537
#else
1528
1538
add_assoc_bool (return_value , "JIS-mapped Japanese Font Support" , 0 );
@@ -1655,13 +1665,9 @@ PHP_FUNCTION(imageloadfont)
1655
1665
body_size = font -> w * font -> h * font -> nchars ;
1656
1666
}
1657
1667
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 )) {
1665
1671
php_error_docref (NULL TSRMLS_CC , E_WARNING , "Error reading font, invalid font header" );
1666
1672
efree (font );
1667
1673
php_stream_close (stream );
@@ -1984,7 +1990,7 @@ PHP_FUNCTION(imagesavealpha)
1984
1990
}
1985
1991
/* }}} */
1986
1992
1987
- #if HAVE_GD_BUNDLED
1993
+ #if defined( HAVE_GD_BUNDLED ) || defined( HAVE_LIBGD21 )
1988
1994
/* {{{ proto bool imagelayereffect(resource im, int effect)
1989
1995
Set the alpha blending flag to use the bundled libgd layering effects */
1990
1996
PHP_FUNCTION (imagelayereffect )
@@ -2375,7 +2381,7 @@ PHP_FUNCTION(imagetypes)
2375
2381
#ifdef HAVE_GD_WBMP
2376
2382
ret |= 8 ;
2377
2383
#endif
2378
- #if defined(HAVE_GD_XPM ) && defined(HAVE_GD_BUNDLED )
2384
+ #if defined(HAVE_GD_XPM ) && ( defined(HAVE_GD_BUNDLED ) || defined( HAVE_LIBGD21 ) )
2379
2385
ret |= 16 ;
2380
2386
#endif
2381
2387
@@ -2387,6 +2393,23 @@ PHP_FUNCTION(imagetypes)
2387
2393
}
2388
2394
/* }}} */
2389
2395
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
+
2390
2413
/* {{{ _php_image_type
2391
2414
*/
2392
2415
static const char php_sig_gd2 [3 ] = {'g' , 'd' , '2' };
@@ -2416,7 +2439,7 @@ static int _php_image_type (char data[8])
2416
2439
gdIOCtx * io_ctx ;
2417
2440
io_ctx = gdNewDynamicCtxEx (8 , data , 0 );
2418
2441
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 ) {
2420
2443
#if HAVE_LIBGD204
2421
2444
io_ctx -> gd_free (io_ctx );
2422
2445
#else
@@ -2662,7 +2685,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
2662
2685
case PHP_GDIMG_TYPE_GD2PART :
2663
2686
im = (* func_p )(fp , srcx , srcy , width , height );
2664
2687
break ;
2665
- #if defined(HAVE_GD_XPM ) && defined(HAVE_GD_BUNDLED )
2688
+ #if defined(HAVE_GD_XPM ) && ( defined(HAVE_GD_BUNDLED ) || defined( HAVE_LIBGD21 ) )
2666
2689
case PHP_GDIMG_TYPE_XPM :
2667
2690
im = gdImageCreateFromXpm (file );
2668
2691
break ;
@@ -2752,7 +2775,7 @@ PHP_FUNCTION(imagecreatefromxbm)
2752
2775
/* }}} */
2753
2776
#endif /* HAVE_GD_XBM */
2754
2777
2755
- #if defined(HAVE_GD_XPM ) && defined(HAVE_GD_BUNDLED )
2778
+ #if defined(HAVE_GD_XPM ) && ( defined(HAVE_GD_BUNDLED ) || defined( HAVE_LIBGD21 ) )
2756
2779
/* {{{ proto resource imagecreatefromxpm(string filename)
2757
2780
Create a new image from XPM file or URL */
2758
2781
PHP_FUNCTION (imagecreatefromxpm )
@@ -2960,7 +2983,7 @@ static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char
2960
2983
2961
2984
/* {{{ proto int imagexbm(int im, string filename [, int foreground])
2962
2985
Output XBM image to browser or file */
2963
- #if HAVE_GD_BUNDLED
2986
+ #if defined( HAVE_GD_BUNDLED ) || defined( HAVE_LIBGD21 )
2964
2987
PHP_FUNCTION (imagexbm )
2965
2988
{
2966
2989
_php_image_output_ctx (INTERNAL_FUNCTION_PARAM_PASSTHRU , PHP_GDIMG_TYPE_XBM , "XBM" , gdImageXbmCtx );
@@ -5253,8 +5276,10 @@ PHP_FUNCTION(imageantialias)
5253
5276
RETURN_TRUE ;
5254
5277
}
5255
5278
/* }}} */
5279
+ #endif
5256
5280
5257
5281
5282
+ #if defined(HAVE_GD_BUNDLED ) || defined(HAVE_LIBGD21 )
5258
5283
/* {{{ proto void imagecrop(resource im, array rect)
5259
5284
Crop an image using the given coordinates and size, x, y, width and height. */
5260
5285
PHP_FUNCTION (imagecrop )
0 commit comments