-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
Conversation
There was a problem hiding this 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"); |
There was a problem hiding this comment.
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:
zend_value_error("$(width) and $(height) cannot be both negative"); | |
zend_value_error("$width and $height cannot be both negative"); |
There was a problem hiding this 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.
There was a problem hiding this 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"); |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
…lues. Throwing a ValueError in this particular case.
There was a problem hiding this 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!
Throwing a ValueError in this particular case.