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

Cater to optional support of GD/GD2 image formats #15006

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

cmb69
Copy link
Member

@cmb69 cmb69 commented Jul 18, 2024

Prior to libgd 2.3.0, support for the proprietary GD and GD2 image formats has was mandatory. However, as of that version libgd can be built without support for these formats[1], and as of libgd 2.3.3 by default these formats are not supported[2].

If libgd is built without support for a certain image format, the respective reader and writer functions are still defined, but they are NOPs. However, PHP GD users expect the reader and writer function to only be defined, if there is actual support, so we're checking for the support during build time, and declare the HAVE_GD_GD macro only if support for the GD and GD2 image formats is available.

We do not change the bundled libgd to make support for these formats optional, yet.

[1] libgd/libgd#428
[2] https://github.com/libgd/libgd/blob/master/CHANGELOG.md#233---2021-09-12


Just the first step. Yet missing:

  • report support via gd_info(), PHP info and imagetypes()
  • cater to imagecreatefromstring()
  • adapt tests to properly check for availability

and maybe more. I'll continue to work on this ASAP, but wouldn't be sad if someone else would take over, or at least help with testing on Linux with system libgd.

Prior to libgd 2.3.0, support for the proprietary GD and GD2 image
formats has was mandatory.  However, as of that version libgd can be
built without support for these formats[1], and as of libgd 2.3.3 by
default these formats are not supported[2].

If libgd is built without support for a certain image format, the
respective reader and writer functions are still defined, but they are
NOPs.  However, PHP GD users expect the reader and writer function to
only be defined, if there is actual support, so we're checking for the
support during build time, and declare the `HAVE_GD_GD` macro only if
support for the GD and GD2 image formats is available.

We do not change the bundled libgd to make support for these formats
optional, yet.

[1] <libgd/libgd#428>
[2] <https://github.com/libgd/libgd/blob/master/CHANGELOG.md#233---2021-09-12>
@orlitzky
Copy link
Contributor

I updated the SKIPIFs here: https://github.com/orlitzky/php-src/tree/gd-detection

Ignore the first commit; to minimize the noise, it deletes all tests that fail with external libgd for unrelated reasons.

Now,

  • External libgd without gd/gd2 support: all tests pass
  • External libgd with gd/gd2 support: all tests pass EXCEPT ext/gd/tests/bug73869.phpt

It does look like the patch for bug 73869 made it into upstream libgd, so I'm not sure what the problem is there. Here's the log:

$ cat ext/gd/tests/bug73869.log 

---- EXPECTED OUTPUT
Warning: imagecreatefromgd2(): "%s" is not a valid GD2 file in %s on line %d
bool(false)

Warning: imagecreatefromgd2(): "%s" is not a valid GD2 file in %s on line %d
bool(false)
---- ACTUAL OUTPUT
Warning: imagecreatefromgd2(): product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully
 in /home/mjo/src/php-src/ext/gd/tests/bug73869.php on line 2

Warning: imagecreatefromgd2(): "/home/mjo/src/php-src/ext/gd/tests/bug73869a.gd2" is not a valid GD2 file in /home/mjo/src/php-src/ext/gd/tests/bug73869.php on line 2
bool(false)

Warning: imagecreatefromgd2(): one parameter to a memory allocation multiplication is negative or zero, failing operation gracefully
 in /home/mjo/src/php-src/ext/gd/tests/bug73869.php on line 3

Warning: imagecreatefromgd2(): "/home/mjo/src/php-src/ext/gd/tests/bug73869b.gd2" is not a valid GD2 file in /home/mjo/src/php-src/ext/gd/tests/bug73869.php on line 3
bool(false)
---- FAILED

@cmb69
Copy link
Member Author

cmb69 commented Jul 18, 2024

External libgd with gd/gd2 support: all tests pass EXCEPT ext/gd/tests/bug73869.phpt

I think that is due to our bundled libgd has

if (*ncx <= 0 || *ncy <= 0 || *ncx > INT_MAX / *ncy) {

but system libgd calls overflow2() instead (as of libgd 2.3.0), and the latter triggers the additional warnings. I think we should port that patch for our master branch, but for lower branches we would need to adjust the test case.

@orlitzky
Copy link
Contributor

Ok, I pushed two more commits. The second one is trivial, to match both capital and lowercase 'p'. The first should handle the extra warning from the overflow by making the additional warning optional. I figure that will be easiest because then if/when you pull the commit into the bundled libgd, you can update the tests (make the warning NON-optional) at the same time and then easily merge them into the same branches.

Support for `imagetypes()` implies to define the respective userland
constant `IMG_GD`.

We also fix the missing #ifdefs for the reader and writer function
definitions.
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.

None yet

2 participants