Skip to content

ext/gd: imagewebp/imageavif/imagepng/imagejpeg stricter checks quality/speed. #14485

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 Jun 5, 2024

No description provided.

@devnexen devnexen marked this pull request as draft June 5, 2024 17:50
@devnexen devnexen force-pushed the gd_image_exceptions branch from 91e9210 to 925dcc3 Compare June 5, 2024 20:06
@devnexen devnexen changed the title ext/gd: imagewebp/imageavif/imagepng stricter checks for quality/speed. ext/gd: imagewebp/imageavif/imagepng/imagejpeg stricter checks quality/speed. Jun 5, 2024
@devnexen devnexen marked this pull request as ready for review June 5, 2024 20:42
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 right

ext/gd/gd.c Outdated
gdImageJpegCtx(im, ctx, (int) quality);
break;
#endif
#ifdef HAVE_GD_WEBP
case PHP_GDIMG_TYPE_WEBP:
if (quality == -1) {
if (quality < -1) {
zend_argument_value_error(3, "must be at least -1");
Copy link
Member

Choose a reason for hiding this comment

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

The "greater than or equal to" style is more commonly used with "at least" having only a few hits in the codebase.

ext/gd/gd.c Outdated
zend_argument_value_error(3, "must be at least -1");
ctx->gd_free(ctx);
RETURN_THROWS();
} else if (quality == -1) {
Copy link
Member

Choose a reason for hiding this comment

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

This "else if" branch is actually unnecessary:

if (quality == -1) {
quality = 80;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

yes saw that but was wondering if this is a "recent" addition was wondering why it is in place here then.

Copy link
Member

Choose a reason for hiding this comment

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

It seems that the code previously used virtual functions so that might've been harder to see what the possible call targets are and therefore harder to see what's necessary and not. I'm fine with keeping this of course.
It's been in the library part since 2015: 00ba7e6

Copy link
Member Author

Choose a reason for hiding this comment

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

I see. happy to remove anyway :)

@devnexen devnexen force-pushed the gd_image_exceptions branch from 925dcc3 to d7b4eb9 Compare June 5, 2024 21:40
@devnexen devnexen closed this in 7b2ca07 Jun 5, 2024
@thg2k
Copy link
Contributor

thg2k commented Jun 9, 2024

@nielsdos I'd like to point out that the default quality of 80 that was dropped in this PR was only added to system gd from version 2.2.0, while we require 2.1.0 as minimum version, so this can theoretically break installations linking to system libgd 2.1 (no idea if any exists).

libgd/libgd@c7e5dc6

@nielsdos
Copy link
Member

nielsdos commented Jun 9, 2024

Thanks for pointing this out.
Version 2.1.0 is pretty old, so perhaps we should bump our version requirement; or for now reintroduce the check. @devnexen What do you think?

@devnexen
Copy link
Member Author

devnexen commented Jun 9, 2024

Definitively, 2.1.0 is 10 years+ old it seems.

@nielsdos
Copy link
Member

Definitively, 2.1.0 is 10 years+ old it seems.

Then feel free to just bump it.

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