[PHP-CVS] cvs: php4(PHP_4_3) /ext/standard image.c
helly Fri Feb 14 14:46:21 2003 EDT Modified files: (Branch: PHP_4_3) /php4/ext/standard image.c Log: MFH: xbm improvements Index: php4/ext/standard/image.c diff -u php4/ext/standard/image.c:1.72.2.9 php4/ext/standard/image.c:1.72.2.10 --- php4/ext/standard/image.c:1.72.2.9 Thu Feb 13 02:16:55 2003 +++ php4/ext/standard/image.c Fri Feb 14 14:46:21 2003 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: image.c,v 1.72.2.9 2003/02/13 07:16:55 sniper Exp $ */ +/* $Id: image.c,v 1.72.2.10 2003/02/14 19:46:21 helly Exp $ */ #include php.h #include stdio.h @@ -956,11 +956,10 @@ /* {{{ php_get_xbm */ -#define MAX_XBM_LINE_SIZE 255 static int php_get_xbm(php_stream *stream, struct gfxinfo **result TSRMLS_DC) { -char fline[MAX_XBM_LINE_SIZE]; -char iname[MAX_XBM_LINE_SIZE]; +char *fline; +char *iname; char *type; int value; unsigned int width = 0, height = 0; @@ -971,12 +970,8 @@ if (php_stream_rewind(stream)) { return 0; } - while (php_stream_gets(stream, fline, MAX_XBM_LINE_SIZE)) { - fline[MAX_XBM_LINE_SIZE-1] = '\0'; - if (strlen(fline) == MAX_XBM_LINE_SIZE-1) { - return 0; - } - + while ((fline=php_stream_gets(stream, NULL, 0)) != NULL) { + iname = estrdup(fline); /* simple way to get necessary buffer of +required size */ if (sscanf(fline, #define %s %d, iname, value) == 2) { if (!(type = strrchr(iname, '_'))) { type = iname; @@ -987,16 +982,23 @@ if (!strcmp(width, type)) { width = (unsigned int) value; if (height) { + efree(iname); break; } } if (!strcmp(height, type)) { height = (unsigned int) value; if (width) { + efree(iname); break; } } } + efree(fline); + efree(iname); + } + if (fline) { + efree(fline); } if (width height) { -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4(PHP_4_3) /ext/standard image.c
helly Thu Dec 5 07:47:22 2002 EDT Modified files: (Branch: PHP_4_3) /php4/ext/standard image.c Log: MFH: swc zlib\nMFH: return FALSE Index: php4/ext/standard/image.c diff -u php4/ext/standard/image.c:1.72.2.4 php4/ext/standard/image.c:1.72.2.5 --- php4/ext/standard/image.c:1.72.2.4 Mon Nov 18 11:53:04 2002 +++ php4/ext/standard/image.c Thu Dec 5 07:47:22 2002 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: image.c,v 1.72.2.4 2002/11/18 16:53:04 helly Exp $ */ +/* $Id: image.c,v 1.72.2.5 2002/12/05 12:47:22 helly Exp $ */ #include php.h #include stdio.h @@ -80,7 +80,9 @@ REGISTER_LONG_CONSTANT(IMAGETYPE_JP2, IMAGE_FILETYPE_JP2, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT(IMAGETYPE_JPX, IMAGE_FILETYPE_JPX, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT(IMAGETYPE_JB2, IMAGE_FILETYPE_JB2, CONST_CS | CONST_PERSISTENT); +#if HAVE_ZLIB REGISTER_LONG_CONSTANT(IMAGETYPE_SWC, IMAGE_FILETYPE_SWC, CONST_CS | CONST_PERSISTENT); +#endif REGISTER_LONG_CONSTANT(IMAGETYPE_IFF, IMAGE_FILETYPE_IFF, CONST_CS | CONST_PERSISTENT); return SUCCESS; } @@ -823,6 +825,7 @@ int arg_c = ZEND_NUM_ARGS(); if ((arg_c!=1) || zend_get_parameters_ex(arg_c, p_image_type) == FAILURE) { + RETVAL_FALSE; WRONG_PARAM_COUNT; } convert_to_long_ex(p_image_type); @@ -894,6 +897,7 @@ case 1: if (zend_get_parameters_ex(1, arg1) == FAILURE) { + RETVAL_FALSE; WRONG_PARAM_COUNT; } convert_to_string_ex(arg1); @@ -901,20 +905,21 @@ case 2: if (zend_get_parameters_ex(2, arg1, info) == FAILURE) { + RETVAL_FALSE; WRONG_PARAM_COUNT; } zval_dtor(*info); if (array_init(*info) == FAILURE) { - return; + RETURN_FALSE; } convert_to_string_ex(arg1); break; default: + RETVAL_FALSE; WRONG_PARAM_COUNT; - break; } stream = php_stream_open_wrapper(Z_STRVAL_PP(arg1), rb, REPORT_ERRORS|IGNORE_PATH|ENFORCE_SAFE_MODE, NULL); @@ -974,7 +979,7 @@ if (array_init(return_value) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_ERROR, Unable to initialize array); efree(result); - return; + RETURN_FALSE; } add_index_long(return_value, 0, result-width); add_index_long(return_value, 1, result-height); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php4(PHP_4_3) /ext/standard image.c
On Thu, 5 Dec 2002, Marcus Boerger wrote: helly Thu Dec 5 07:47:22 2002 EDT Modified files: (Branch: PHP_4_3) /php4/ext/standardimage.c Log: MFH: swc zlib\nMFH: return FALSE \n doesn't work on the command line :-) Derick -- - Derick Rethans http://derickrethans.nl/ PHP Magazine - PHP Magazine for Professionals http://php-mag.net/ - -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php4(PHP_4_3) /ext/standard image.c
array_init() can no longer fail, because it means that ZE was unable to allocate memory at which point ZE will cease the script execution. So, if there are any existing checks for return value of array_init() or any other e* memory allocation functions, those checks can be safely removed since they will never happen. Ilia On December 5, 2002 07:47 am, Marcus Boerger wrote: helly Thu Dec 5 07:47:22 2002 EDT Modified files: (Branch: PHP_4_3) /php4/ext/standardimage.c Log: MFH: swc zlib\nMFH: return FALSE Index: php4/ext/standard/image.c diff -u php4/ext/standard/image.c:1.72.2.4 php4/ext/standard/image.c:1.72.2.5 --- php4/ext/standard/image.c:1.72.2.4Mon Nov 18 11:53:04 2002 +++ php4/ext/standard/image.c Thu Dec 5 07:47:22 2002 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: image.c,v 1.72.2.4 2002/11/18 16:53:04 helly Exp $ */ +/* $Id: image.c,v 1.72.2.5 2002/12/05 12:47:22 helly Exp $ */ #include php.h #include stdio.h @@ -80,7 +80,9 @@ REGISTER_LONG_CONSTANT(IMAGETYPE_JP2, IMAGE_FILETYPE_JP2, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT(IMAGETYPE_JPX, IMAGE_FILETYPE_JPX, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT(IMAGETYPE_JB2, IMAGE_FILETYPE_JB2, CONST_CS | CONST_PERSISTENT); +#if HAVE_ZLIB REGISTER_LONG_CONSTANT(IMAGETYPE_SWC, IMAGE_FILETYPE_SWC, CONST_CS | CONST_PERSISTENT); +#endif REGISTER_LONG_CONSTANT(IMAGETYPE_IFF, IMAGE_FILETYPE_IFF, CONST_CS | CONST_PERSISTENT); return SUCCESS; } @@ -823,6 +825,7 @@ int arg_c = ZEND_NUM_ARGS(); if ((arg_c!=1) || zend_get_parameters_ex(arg_c, p_image_type) == FAILURE) { + RETVAL_FALSE; WRONG_PARAM_COUNT; } convert_to_long_ex(p_image_type); @@ -894,6 +897,7 @@ case 1: if (zend_get_parameters_ex(1, arg1) == FAILURE) { + RETVAL_FALSE; WRONG_PARAM_COUNT; } convert_to_string_ex(arg1); @@ -901,20 +905,21 @@ case 2: if (zend_get_parameters_ex(2, arg1, info) == FAILURE) { + RETVAL_FALSE; WRONG_PARAM_COUNT; } zval_dtor(*info); if (array_init(*info) == FAILURE) { - return; + RETURN_FALSE; } convert_to_string_ex(arg1); break; default: + RETVAL_FALSE; WRONG_PARAM_COUNT; - break; } stream = php_stream_open_wrapper(Z_STRVAL_PP(arg1), rb, REPORT_ERRORS|IGNORE_PATH|ENFORCE_SAFE_MODE, NULL); @@ -974,7 +979,7 @@ if (array_init(return_value) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_ERROR, Unable to initialize array); efree(result); - return; + RETURN_FALSE; } add_index_long(return_value, 0, result-width); add_index_long(return_value, 1, result-height); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php4(PHP_4_3) /ext/standard image.c
On December 5, 2002 10:26 am, Marcus Börger wrote: At 16:23 05.12.2002, Ilia A. wrote: array_init() can no longer fail, because it means that ZE was unable to allocate memory at which point ZE will cease the script execution. So, if there are any existing checks for return value of array_init() or any other e* memory allocation functions, those checks can be safely removed since they will never happen. Yes you're right - and unfortunately there are hundreds of such cases in PHP. True, but if you are already modifying the code please remove those checks. This way we'll slowly, but surely get rid of unnecessary code ;) Ilia -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4(PHP_4_3) /ext/standard image.c
helly Thu Dec 5 10:52:35 2002 EDT Modified files: (Branch: PHP_4_3) /php4/ext/standard image.c Log: MFH: Remove unnecessary code here Index: php4/ext/standard/image.c diff -u php4/ext/standard/image.c:1.72.2.5 php4/ext/standard/image.c:1.72.2.6 --- php4/ext/standard/image.c:1.72.2.5 Thu Dec 5 07:47:22 2002 +++ php4/ext/standard/image.c Thu Dec 5 10:52:35 2002 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: image.c,v 1.72.2.5 2002/12/05 12:47:22 helly Exp $ */ +/* $Id: image.c,v 1.72.2.6 2002/12/05 15:52:35 helly Exp $ */ #include php.h #include stdio.h @@ -910,9 +910,7 @@ } zval_dtor(*info); - if (array_init(*info) == FAILURE) { - RETURN_FALSE; - } + array_init(*info); convert_to_string_ex(arg1); break; @@ -976,11 +974,7 @@ php_stream_close(stream); if (result) { - if (array_init(return_value) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_ERROR, Unable to initialize array); - efree(result); - RETURN_FALSE; - } + array_init(return_value); add_index_long(return_value, 0, result-width); add_index_long(return_value, 1, result-height); add_index_long(return_value, 2, itype); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4(PHP_4_3) /ext/standard image.c
helly Mon Nov 18 10:50:49 2002 EDT Modified files: (Branch: PHP_4_3) /php4/ext/standard image.c Log: Fixing unsigned/signed problems (and i thought about it before...)\n Index: php4/ext/standard/image.c diff -u php4/ext/standard/image.c:1.72.2.2 php4/ext/standard/image.c:1.72.2.3 --- php4/ext/standard/image.c:1.72.2.2 Mon Nov 18 10:46:01 2002 +++ php4/ext/standard/image.c Mon Nov 18 10:50:49 2002 @@ -16,7 +16,8 @@ | Marcus Boerger [EMAIL PROTECTED] | +--+ */ -/* $Id: image.c,v 1.72.2.2 2002/11/18 15:46:01 derick Exp $ */ + +/* $Id: image.c,v 1.72.2.3 2002/11/18 15:50:49 helly Exp $ */ #include php.h #include stdio.h @@ -90,7 +91,7 @@ static struct gfxinfo *php_handle_gif (php_stream * stream TSRMLS_DC) { struct gfxinfo *result = NULL; - char dim[5]; + unsigned char dim[5]; if (php_stream_seek(stream, 3, SEEK_CUR)) return NULL; @@ -113,7 +114,7 @@ static struct gfxinfo *php_handle_psd (php_stream * stream TSRMLS_DC) { struct gfxinfo *result = NULL; - char dim[8]; + unsigned char dim[8]; if (php_stream_seek(stream, 11, SEEK_CUR)) return NULL; @@ -134,7 +135,7 @@ static struct gfxinfo *php_handle_bmp (php_stream * stream TSRMLS_DC) { struct gfxinfo *result = NULL; - char dim[12]; + unsigned char dim[12]; if (php_stream_seek(stream, 15, SEEK_CUR)) return NULL; @@ -275,7 +276,7 @@ static struct gfxinfo *php_handle_png (php_stream * stream TSRMLS_DC) { struct gfxinfo *result = NULL; - char dim[8]; + unsigned char dim[8]; if (php_stream_seek(stream, 8, SEEK_CUR)) return NULL; -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4(PHP_4_3) /ext/standard image.c
helly Mon Nov 18 11:53:05 2002 EDT Modified files: (Branch: PHP_4_3) /php4/ext/standard image.c Log: MFH: Added colordepth for png\n Index: php4/ext/standard/image.c diff -u php4/ext/standard/image.c:1.72.2.3 php4/ext/standard/image.c:1.72.2.4 --- php4/ext/standard/image.c:1.72.2.3 Mon Nov 18 10:50:49 2002 +++ php4/ext/standard/image.c Mon Nov 18 11:53:04 2002 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: image.c,v 1.72.2.3 2002/11/18 15:50:49 helly Exp $ */ +/* $Id: image.c,v 1.72.2.4 2002/11/18 16:53:04 helly Exp $ */ #include php.h #include stdio.h @@ -276,7 +276,15 @@ static struct gfxinfo *php_handle_png (php_stream * stream TSRMLS_DC) { struct gfxinfo *result = NULL; - unsigned char dim[8]; + unsigned char dim[9]; +/* Width: 4 bytes + * Height: 4 bytes + * Bit depth: 1 byte + * Color type: 1 byte + * Compression method: 1 byte + * Filter method: 1 byte + * Interlace method: 1 byte + */ if (php_stream_seek(stream, 8, SEEK_CUR)) return NULL; @@ -287,6 +295,7 @@ result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo)); result-width = (((unsigned int)dim[0]) 24) + (((unsigned int)dim[1]) 16) + (((unsigned int)dim[2]) 8) + ((unsigned int)dim[3]); result-height = (((unsigned int)dim[4]) 24) + (((unsigned int)dim[5]) 16) + (((unsigned int)dim[6]) 8) + ((unsigned int)dim[7]); + result-bits = (unsigned int)dim[8]; return result; } /* }}} */ -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php