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
Image format detection false positives with external GD #12019
Comments
When freetype support is missing from gd, PHP actually fails to build. The feature detection looks for a function that's always there, but then PHP tries to call a function that is only defined conditionally:
|
We currently check for, say, AVIF support by attempting to link a program that calls libgd's gdImageCreateFromAvif() function. But perversely, that function always exists in libgd; moreover when AVIF support is missing it emits a warning and returns normally. Thus our straightforward link test becomes not so straightforward. This commit adds a new macro PHP_GD_CHECK_FORMAT that compiles, links, and runs a test program instead. The test program overrides that "emit a warning" handler so that the program actually fails if the format we're looking for is not supported. This fixes detection of AVIF and the other formats we check for in an external libgd. Closes phpGH-12019
We currently check for, say, AVIF support by attempting to link a program that calls libgd's gdImageCreateFromAvif() function. But perversely, that function always exists in libgd; moreover when AVIF support is missing it emits a warning and returns normally. Thus our straightforward link test becomes not so straightforward. This commit adds a new macro PHP_GD_CHECK_FORMAT that compiles, links, and runs a test program instead. The test program overrides that "emit a warning" handler so that the program actually fails if the format we're looking for is not supported. This fixes detection of AVIF and the other formats we check for in an external libgd. Closes phpGH-12019
Thank you! it helps #7526 |
- Use gdFontCacheShutdown() to detect freetype Currently we look for gdImageStringFT() to determine whether or not gd has freetype support... but that function always exists. This leads PHP to believe that gd has freetype support when it does not, and can lead to build failures. The gdFontCacheShutdown() function, on the other hand, is only present when gd was built with freetype support. Let's use that instead. - Fix GD image format detection We currently check for, say, AVIF support by attempting to link a program that calls libgd's gdImageCreateFromAvif() function. But perversely, that function always exists in libgd; moreover when AVIF support is missing it emits a warning and returns normally. Thus our straightforward link test becomes not so straightforward. This commit adds a new macro PHP_GD_CHECK_FORMAT that compiles, links, and runs a test program instead. The test program overrides that "emit a warning" handler so that the program actually fails if the format we're looking for is not supported. This fixes detection of AVIF and the other formats we check for in an external libgd. - ext/gd/tests/bug77391.phpt: skip if gd lacks BMP support I don't actually know how to remove BMP support from libgd, but PHP has a ./configure test for it, so we should probably treat it as optional. Closes phpGH-12019
- Use gdFontCacheShutdown() to detect freetype Currently we look for gdImageStringFT() to determine whether or not gd has freetype support... but that function always exists. This leads PHP to believe that gd has freetype support when it does not, and can lead to build failures. The gdFontCacheShutdown() function, on the other hand, is only present when gd was built with freetype support. Let's use that instead. - Fix GD image format detection We currently check for, say, AVIF support by attempting to link a program that calls libgd's gdImageCreateFromAvif() function. But perversely, that function always exists in libgd; moreover when AVIF support is missing it emits a warning and returns normally. Thus our straightforward link test becomes not so straightforward. This commit adds a new macro PHP_GD_CHECK_FORMAT that compiles, links, and runs a test program instead. The test program overrides that "emit a warning" handler so that the program actually fails if the format we're looking for is not supported. This fixes detection of AVIF and the other formats we check for in an external libgd. - ext/gd/tests/bug77391.phpt: skip if gd lacks BMP support I don't actually know how to remove BMP support from libgd, but PHP has a ./configure test for it, so we should probably treat it as optional. Closes phpGH-12019
- Use gdFontCacheShutdown() to detect freetype Currently we look for gdImageStringFT() to determine whether or not gd has freetype support... but that function always exists. This leads PHP to believe that gd has freetype support when it does not, and can lead to build failures. The gdFontCacheShutdown() function, on the other hand, is only present when gd was built with freetype support. Let's use that instead. - Fix GD image format detection We currently check for, say, AVIF support by attempting to link a program that calls libgd's gdImageCreateFromAvif() function. But perversely, that function always exists in libgd; moreover when AVIF support is missing it emits a warning and returns normally. Thus our straightforward link test becomes not so straightforward. This commit adds a new macro PHP_GD_CHECK_FORMAT that compiles, links, and runs a test program instead. The test program overrides that "emit a warning" handler so that the program actually fails if the format we're looking for is not supported. This fixes detection of AVIF and the other formats we check for in an external libgd. - ext/gd/tests/bug77391.phpt: skip if gd lacks BMP support I don't actually know how to remove BMP support from libgd, but PHP has a ./configure test for it, so we should probably treat it as optional. Closes GH-12019
This breaks detection of libgd supported graphic formats completely on a FreeBSD-13.2 system: configure:37620: checking for working gdImageCreateFromWebp in libgd /usr/local/include is missing from the include path! |
PHP itself tries to Are you somehow adding it to your include path after |
PHP-8.3.2 compiles fine with external libgd. The problem here is the test code, which tries to include gd.h without properly set include path (despite having set a correct library path). |
It would be helpful to know what
returns on this system. I'm starting to suspect that,
doesn't actually add |
$ pkg-config --cflags gdlib |
Ok, thanks, my mistake then. I thought the |
Probably something like this needs to be done in ext/gd/config.m4 at that check:
|
In commit 85e5635, a feature test for the various libgd image formats was added. That test however erroneously omits the GDLIB_CFLAGS (from pkg-config) during compilation. This can lead to build failuress and therefore false negatives from the test. Here, we add $GDLIB_CFLAGS to $CFLAGS for the duration of the test. Moreover, we replace $GD_SHARED_LIBADD with $GDLIB_LIBS in the same test. The variable $GD_SHARED_LIBADD is actually empty when we try to use it. Fortunately(?), the library flags are appended elsewhere, so this was not causing a problem. But of course it's better to explicitly do the right thing. Closes phpGH-12019
In commit 85e5635, a feature test for the various libgd image formats was added. That test however erroneously omits the GDLIB_CFLAGS (from pkg-config) during compilation. This can lead to build failures and therefore false negatives from the test. Here, we add $GDLIB_CFLAGS to $CFLAGS for the duration of the test. Moreover, we replace $GD_SHARED_LIBADD with $GDLIB_LIBS in the same test. The variable $GD_SHARED_LIBADD is actually empty when we try to use it. Fortunately(?), the library flags are appended elsewhere, so this was not causing a problem. But of course it's better to explicitly do the right thing. Closes phpGH-12019
Ok, please test if you can: #13724 |
In commit 85e5635, a feature test for the various libgd image formats was added. That test however erroneously omits the GDLIB_CFLAGS (from pkg-config) during compilation. This can lead to build failures and therefore false negatives from the test. Here, we add $GDLIB_CFLAGS to $CFLAGS for the duration of the test. Closes phpGH-12019
* PHP-8.2: Fix GH-12019: ext/gd/config.m4: don't forget GDLIB_CFLAGS in feature tests
* PHP-8.3: Fix GH-12019: ext/gd/config.m4: don't forget GDLIB_CFLAGS in feature tests
Description
To check for supported image types, PHP (
ext/gd/config.m4
) tries to link against libgd:However, upstream libgd declares those functions unconditionally. Using AVIF as an example,
gdImageCreateFromAvif
is declared unconditionally at https://github.com/libgd/libgd/blob/master/src/gd.h#L683, and then implemented (when AVIF support is disabled) in https://github.com/libgd/libgd/blob/master/src/gd_avif.c#L674. As a result, PHP decides that it supports AVIF images when it does not.In particular this causes
imagetypes()
to return types that PHP does not actually support. It also results in several PHP functions being made available that should not be, e.g.Finally, those two issues lead to test failures when format-specific are not skipped as they should be:
Thus when some formats are missing from the system gd, there are a few more test failures to add to the list in #11252
PHP Version
git head
Operating System
No response
The text was updated successfully, but these errors were encountered: