[php-src] Issue #12019: Image format detection false positives with external GD

From: Date: Tue, 22 Aug 2023 13:07:15 +0000
Subject: [php-src] Issue #12019: Image format detection false positives with external GD
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-245220@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/12019
Author: orlitzky

### Description

To check for supported image types, PHP (ext/gd/config.m4) tries to link against libgd:

```m4
AC_DEFUN([PHP_GD_CHECK_VERSION],[
  PHP_CHECK_LIBRARY(gd, gdImageCreateFromPng,          [AC_DEFINE(HAVE_GD_PNG,               1, [
])], [], [ $GD_SHARED_LIBADD ])
  PHP_CHECK_LIBRARY(gd, gdImageCreateFromAvif,         [AC_DEFINE(HAVE_GD_AVIF,              1, [
])], [], [ $GD_SHARED_LIBADD ])
  ...
])
```

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.

```C
#ifdef HAVE_GD_AVIF
/* {{{ Create a new image from AVIF file or URL */
PHP_FUNCTION(imagecreatefromavif)
{
        _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_AVIF,
"AVIF", gdImageCreateFromAvif, gdImageCreateFromAvifCtx);
}
/* }}} */
#endif /* HAVE_GD_AVIF */
```

Finally, those two issues lead to test failures when format-specific are not skipped as they should
be:

```
$ head ./ext/gd/tests/imagecreatefromstring_avif.phpt 
--TEST--
imagecreatefromstring() - AVIF format
--EXTENSIONS--
gd
--SKIPIF--
<?php
if (!(imagetypes() & IMG_AVIF)) {
    die('skip AVIF support required');
}
?>
```

Thus when some formats are missing from the system gd, there are a few more test failures to add to
the list in https://github.com/php/php-src/issues/11252

### PHP Version

git head

### Operating System

_No response_


Thread (1 message)

  • orlitzky
« previous php.bugs (#245220) next »