ext/gd: calls with array types check strengthening.#18005
ext/gd: calls with array types check strengthening.#18005devnexen wants to merge 1 commit intophp:masterfrom
Conversation
Girgias
left a comment
There was a problem hiding this comment.
Feels like adding a common function php_gd_zval_try_get_c_int() seems like a good idea.
ext/gd/gd.c
Outdated
| } | ||
| stylearr[index++] = tmp; |
There was a problem hiding this comment.
Isn't there a possibility of int under/overflow ?
ext/gd/gd.c
Outdated
|
|
||
| if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "x", sizeof("x") -1)) != NULL) { | ||
| rect.x = zval_get_long(tmp); | ||
| r = zval_get_long(tmp); |
ext/gd/gd.c
Outdated
| if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "y", sizeof("y") - 1)) != NULL) { | ||
| rect.y = zval_get_long(tmp); | ||
| r = zval_get_long(tmp); | ||
| if (ZEND_LONG_EXCEEDS_INT(r)) { |
ext/gd/gd.c
Outdated
|
|
||
| if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "width", sizeof("width") - 1)) != NULL) { | ||
| rect.width = zval_get_long(tmp); | ||
| r = zval_get_long(tmp); |
ext/gd/gd.c
Outdated
|
|
||
| if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "height", sizeof("height") - 1)) != NULL) { | ||
| rect.height = zval_get_long(tmp); | ||
| r = zval_get_long(tmp); |
bea99f9 to
3233235
Compare
ext/gd/gd.c
Outdated
| } | ||
| /* }}} */ | ||
|
|
||
| static bool _php_gd_zval_try_get_c_int(zval *tmp, const char *field, int *res) { |
There was a problem hiding this comment.
Symbols starting with _ are reserved in C, so please avoid this.
| static bool _php_gd_zval_try_get_c_int(zval *tmp, const char *field, int *res) { | |
| static bool php_gd_zval_try_get_c_int(zval *tmp, const char *field, int *res) { |
There was a problem hiding this comment.
sorry just saw your comment now, agreed.
3645a3c to
f54c5f3
Compare
Girgias
left a comment
There was a problem hiding this comment.
Sorry some more comments that I realized
ext/gd/gd.c
Outdated
| zend_long tmp = zval_try_get_long(item, &failed); | ||
| if (failed) { | ||
| efree(stylearr); | ||
| zend_argument_value_error(2, "value must be of type int, %s given", zend_zval_type_name(item)); |
There was a problem hiding this comment.
Should be a type error? And maybe clarify that its the elements of the style array?
| zend_long tmp = zval_try_get_long(color, &failed); | ||
| if (failed) { | ||
| efree(colors); | ||
| zend_argument_value_error(5, "value must be of type int, %s given", zend_zval_type_name(color)); |
There was a problem hiding this comment.
Ditto type error and clarify value of the hash colors array
ext/gd/tests/gh18005.phpt
Outdated
| echo $e->getMessage() . PHP_EOL; | ||
| } | ||
| try { | ||
| imagefilter($img, IMG_FILTER_SCATTER, 0, 0, array(new A())); |
There was a problem hiding this comment.
Use [] instead of array() (especially as the prior 2 use the short syntax)
f54c5f3 to
32c5b78
Compare
3c3a228 to
c6bae19
Compare
ext/gd/gd.c
Outdated
| zend_long tmp = zval_try_get_long(item, &failed); | ||
| if (failed) { | ||
| efree(stylearr); | ||
| zend_argument_type_error(2, "must only have element of type int, %s given", zend_zval_type_name(item)); |
There was a problem hiding this comment.
| zend_argument_type_error(2, "must only have element of type int, %s given", zend_zval_type_name(item)); | |
| zend_argument_type_error(2, "must only have elements of type int, %s given", zend_zval_type_name(item)); |
ext/gd/gd.c
Outdated
| } | ||
| if (ZEND_LONG_EXCEEDS_INT(tmp)) { | ||
| efree(stylearr); | ||
| zend_argument_type_error(2, "must have element between %d and %d", INT_MIN, INT_MAX); |
There was a problem hiding this comment.
The wording could be improved here too IMO
| zend_long tmp = zval_try_get_long(color, &failed); | ||
| if (failed) { | ||
| efree(colors); | ||
| zend_argument_value_error(5, "value must be of type int, %s given", zend_zval_type_name(color)); |
0e94dd5 to
d8c30cf
Compare
No description provided.