Skip to content

Fix GH-17703: imagescale both width and heigh set with negative values. #17708

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

Closed
wants to merge 1 commit into from

Conversation

devnexen
Copy link
Member

@devnexen devnexen commented Feb 5, 2025

Throwing a ValueError in this particular case.

Copy link
Member

@cmb69 cmb69 left a comment

Choose a reason for hiding this comment

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

Besides the nit below, this looks good to me. Thank you!

ext/gd/gd.c Outdated
@@ -3633,6 +3633,11 @@ PHP_FUNCTION(imagescale)

im = php_gd_libgdimageptr_from_zval_p(IM);

if (tmp_h < 0 && tmp_w < 0) {
zend_value_error("$(width) and $(height) cannot be both negative");
Copy link
Member

Choose a reason for hiding this comment

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

I don't think the parens make sense here:

Suggested change
zend_value_error("$(width) and $(height) cannot be both negative");
zend_value_error("$width and $height cannot be both negative");

Copy link
Member

@cmb69 cmb69 left a comment

Choose a reason for hiding this comment

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

IMO good to go, but maybe @nielsdos wants to review.

Copy link
Member

@nielsdos nielsdos left a comment

Choose a reason for hiding this comment

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

Seems fine for master, but why do this on lower branches? Now people get an exception instead of returning false, no?

ext/gd/gd.c Outdated
@@ -3633,6 +3633,11 @@ PHP_FUNCTION(imagescale)

im = php_gd_libgdimageptr_from_zval_p(IM);

if (tmp_h < 0 && tmp_w < 0) {
zend_value_error("$width and $height cannot be both negative");
Copy link
Member

Choose a reason for hiding this comment

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

We typically construct an argument_value_error-esque wording when doing these kinds of things.
Something like: Argument #2 ($width) and argument #3 ($height) cannot both be negative.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok will change to return false here instead and will do a PR just for master, wdyt ?

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good

Copy link
Member

Choose a reason for hiding this comment

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

I think the patch as it's now doesn't change anything (well, we bail out a bit earlier), since previously the function also returned false if both width and height have been negative. I suggest to apply the previous patch to PHP-8.4+ (the ValueError was already there previously, only the error message changes). Only applying that to master is fine for me, too.

Copy link
Member

Choose a reason for hiding this comment

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

Ah right indeed. I agree.

@devnexen devnexen marked this pull request as ready for review February 5, 2025 18:07
…lues.

Throwing a ValueError in this particular case.
@devnexen devnexen removed the request for review from SakiTakamachi February 5, 2025 18:43
Copy link
Member

@nielsdos nielsdos left a comment

Choose a reason for hiding this comment

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

Sorry for the small review hiccup, looks good now!

@devnexen devnexen closed this in dc7b661 Feb 5, 2025
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.

3 participants