Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ext/gd: calls with array types check strengthening. #18005

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

devnexen
Copy link
Member

@devnexen devnexen commented Mar 8, 2025

No description provided.

Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like adding a common function php_gd_zval_try_get_c_int() seems like a good idea.

ext/gd/gd.c Outdated
Comment on lines 662 to 663
}
stylearr[index++] = tmp;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there a possibility of int under/overflow ?

ext/gd/gd.c Outdated
@@ -3840,28 +3862,48 @@ PHP_FUNCTION(imagecrop)
im = php_gd_libgdimageptr_from_zval_p(IM);

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try get long?

ext/gd/gd.c Outdated
} else {
zend_argument_value_error(2, "must have an \"x\" key");
RETURN_THROWS();
}

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)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try get long?

ext/gd/gd.c Outdated
} else {
zend_argument_value_error(2, "must have a \"y\" key");
RETURN_THROWS();
}

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

ext/gd/gd.c Outdated
} else {
zend_argument_value_error(2, "must have a \"width\" key");
RETURN_THROWS();
}

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto?

@devnexen devnexen force-pushed the gd_to_try_get_long branch from bea99f9 to 3233235 Compare March 8, 2025 21:43
@devnexen devnexen marked this pull request as ready for review March 8, 2025 21:44
@devnexen devnexen marked this pull request as draft March 8, 2025 23:01
@devnexen devnexen marked this pull request as ready for review March 9, 2025 00:14
Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally makes sense to me, maybe @cmb69 wants to have a look?

@@ -3822,6 +3848,22 @@ PHP_FUNCTION(imageantialias)
}
/* }}} */

static bool _php_gd_zval_try_get_c_int(zval *tmp, const char *field, int *res) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Symbols starting with _ are reserved in C, so please avoid this.

Suggested change
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) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants