Commit graph

2341 commits

Author SHA1 Message Date
David Carlier
fe8dffef5d
Fixed GH-18243: imagettftext underflow/overflow on size argument.
close GH-18245
2025-04-05 15:56:45 +01:00
David Carlier
a1620048fb
ext/gd: imagecrop rect argument overflow fixes.
```
ext/gd/libgd/gd.c:2275:14: runtime error: signed integer overflow: 2147483647 + 1 cannot be represented in type 'int'
    #0 0x5d6a2103e1db in php_gd_gdImageCopy /home/dcarlier/Contribs/php-src/ext/gd/libgd/gd.c:2275
    #1 0x5d6a210a2b63 in gdImageCrop /home/dcarlier/Contribs/php-src/ext/gd/libgd/gd_crop.c:57
    #2 0x5d6a21018ca4 in zif_imagecrop /home/dcarlier/Contribs/php-src/ext/gd/gd.c:3575
    #3 0x5d6a21e46e7a in ZEND_DO_ICALL_SPEC_RETVAL_USED_HANDLER /home/dcarlier/Contribs/php-src/Zend/zend_vm_execute.h:1337
    #4 0x5d6a221188da in execute_ex /home/dcarlier/Contribs/php-src/Zend/zend_vm_execute.h:57246
    #5 0x5d6a221366bd in zend_execute /home/dcarlier/Contribs/php-src/Zend/zend_vm_execute.h:61634
    #6 0x5d6a21d107a6 in zend_execute_scripts /home/dcarlier/Contribs/php-src/Zend/zend.c:1895
    #7 0x5d6a21a63409 in php_execute_script /home/dcarlier/Contribs/php-src/main/main.c:2529
    #8 0x5d6a22516d5e in do_cli /home/dcarlier/Contribs/php-src/sapi/cli/php_cli.c:966
    #9 0x5d6a2251981d in main /home/dcarlier/Contribs/php-src/sapi/cli/php_cli.c:1341
    #10 0x7f10d002a3b7 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    #11 0x7f10d002a47a in __libc_start_main_impl ../csu/libc-start.c:360
    #12 0x5d6a20a06da4 in _start (/home/dcarlier/Contribs/php-src/sapi/cli/php+0x2806da4) (BuildId: d9a79c7e0e4872311439d7313cb3a81fe04190a2)
```

close GH-18006
2025-03-28 17:30:25 +00:00
David Carlier
07ceadf7d9
Fix GH-17984: gd calls with array arguments.
close GH-17985
2025-03-07 18:07:14 +00:00
Michael Orlitzky
174a7fe6f9
Fix GH-17891 gh17373.phpt test issue without freetype support
skip if imagefttext() is not available

This test calls imagefttext(), which may not be available if libgd
was built without freetype support.

Closes GH-17910
2025-02-24 07:13:11 +00:00
Michael Orlitzky
065b4ec125
ext/gd/tests: backport optional PNG support
- Three of our gd tests could be skipped with a message about requiring
bundled GD, but those tests don't actually require bundled GD. We
update the messages to mention the specific functions that are
required.

- add SKIPIF stanzas for missing PNG support

The bundled libgd always has PNG support, but an external one may not.

- imagerotate() is always available

Following 59ec80c5, the imagerotate() function is always available. We
may therefore remove its function_exists() checks without harm.

close GH-17894
2025-02-23 16:01:30 +00:00
David Carlier
4d7d01d18e
Fix GH-17772: imagepalettetotruecolor segfault on invalid truecolor pixel.
close GH-17777
2025-02-14 15:28:33 +00:00
Christoph M. Becker
47683487f8
Fix libgd 223: gdImageRotateGeneric() does not properly interpolate
We port the respective upstream fix[1].  We only run the test against
bundled libgd, since external libgd may yield different results.

Cf. <2b26be874d>.

Closes GH-17380.
2025-01-06 20:37:23 +01:00
Christoph M. Becker
ec90367cd8
Fix GH-17373: imagefttext() ignores clipping rect for palette images
We apply the same fix that has been applied to external libgd at least
as of 2.0.29.

To avoid issues regarding minor FreeType rendering differences, the
test case does not compare against an image, but rather checks that all
pixels outside the clipping rect have the background color.

Closes GH-17374.
2025-01-06 14:57:46 +01:00
Christoph M. Becker
2c658f422d
Fix GH-17349: Tiled truecolor filling looses single color transparency
This is porting the relevant part of a previous upstream commit[1] to
align the behavior of our bundled libgd with upstream.  It should be
noted that this only works if the image actually has a transparent
color.

[1] <4770e2b2d5>

Closes GH-17351.
2025-01-04 14:53:18 +01:00
Christoph M. Becker
643a77dda3
Port fix for libgd bug 276
The issue that BMP RLE occasionally swallowed some pixels[1] had been
fixed long ago in libgd, but apparently it has been overlooked to port
it to our bundled libgd.

We also introduce the test helper `test_image_equals_image()` which
compares in-memory images for equality.

[1] <https://github.com/libgd/libgd/issues/276>

Closes GH-17250.
2024-12-25 16:27:20 +01:00
Niels Dossche
6c198e380e
Fix GH-16255: Unexpected nan value in ext/gd/libgd/gd_filter.c
Closes GH-17169.
2024-12-16 19:43:44 +01:00
David Carlier
6f1d8368d8
Merge branch 'PHP-8.2' into PHP-8.3 2024-11-13 12:49:00 +00:00
David Carlier
4124b04e34
Fix GH-16771: imagecreatefromstring overflow on invalid format.
close GH-16776
2024-11-13 12:48:37 +00:00
Niels Dossche
6d6afd9a83
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-16559: UBSan abort in ext/gd/libgd/gd_interpolation.c:1007
2024-10-23 20:09:39 +02:00
Niels Dossche
e1e1e64a32
Fix GH-16559: UBSan abort in ext/gd/libgd/gd_interpolation.c:1007
The `uchar_clamp` function was backported from old code, this backports
it from new code.

Closes GH-16562.
2024-10-23 20:09:12 +02:00
Christoph M. Becker
05176adc4e
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-16427: Unchecked libavif return values
2024-10-14 13:53:42 +02:00
Christoph M. Becker
b817a4f718
Fix GH-16427: Unchecked libavif return values
Prior to libavif 1.1.0, `avifAlloc()` was infallible (it called
`abort()` on OOM conditions); thus, several API functions which used
`avifAlloc()` did not report failure.  That changed as of libavif
1.0.0[1], so checking and handling failure conditions can now be done.
However, due to `avifAlloc()` being fallible as of libavif 1.1.0, this
error checking and handling is mandatory to avoid more serious issues.

[1] <eb02b2ec52/CHANGELOG.md (L273-L281)>

Closes GH-16434.
2024-10-14 13:52:45 +02:00
David Carlier
d612b0a124
Merge branch 'PHP-8.2' into PHP-8.3 2024-10-11 19:38:26 +01:00
David Carlier
f2859a4050
Fix GH-16322: imageaffine overflow on affine argument.
close GH-16334
2024-10-11 19:37:34 +01:00
David Carlier
93a2fe8aac
Revert "Fix GH-16322: overflow on imageaffine matrix argument."
This reverts commit 05114265fb.
2024-10-09 23:57:09 +01:00
David Carlier
05114265fb
Fix GH-16322: overflow on imageaffine matrix argument. 2024-10-09 23:18:23 +01:00
David Carlier
7c43f68c98
Merge branch 'PHP-8.2' into PHP-8.3 2024-10-07 13:05:32 +01:00
David Carlier
a2bdfeff4f
Fix GH-16257 imagescale underflow on RGB channels.
backport of 948bb0a5c2

close GH-16257
2024-10-07 13:05:05 +01:00
David Carlier
fde5e507f6
Merge branch 'PHP-8.2' into PHP-8.3 2024-10-06 11:01:57 +01:00
David Carlier
2d05da2e94
Fix GH-16260: overflow/underflow on imagerotate degrees argument.
close GH-16264
2024-10-06 11:01:17 +01:00
David Carlier
8ff179529a
Merge branch 'PHP-8.2' into PHP-8.3 2024-10-05 11:34:49 +01:00
David Carlier
54973c9366
Fix GH-16232: bitshift overflow on wbmp file content reading.
backport from a8f1d5cab0

close GH-16239
2024-10-05 11:34:31 +01:00
Christoph M. Becker
02a60be24d
Fix skip condition of gh13082.phpt
The test failure is not particularly related to Travis, but rather is
caused by the GD font file to only be suitable for platforms where
`int` stores 32bit values in little endian byte order.  This platform
dependence is documented in the source code[1].  Thus we fix the skip
condition and skip reason accordingly.

An alternative would be to dynamically create the font file just before
running the test, but that appears to be overkill.

[1] <d59691c02f/ext/gd/gd.c (L545-L556)>

Closes GH-14922.
2024-07-14 13:39:49 +02:00
Christoph M. Becker
0ed956dc69
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Add test case for GH-13774
2024-07-14 12:47:25 +02:00
Christoph M. Becker
6d0db52896
Add test case for GH-13774
Besides demonstrating the new behavior, this test also ensures that the
bundled and external libgd now behave the same.  It has to be noted,
though, that we only test one of the five code paths.

Closes GH-14945.
2024-07-14 12:46:37 +02:00
David Carlier
10a94f846d
Merge branch 'PHP-8.2' into PHP-8.3 2024-07-13 16:59:30 +01:00
Denis Ryabov
b456ae8d34
Restore Warning instead of Fatal Error in gd_webp.c
According to the docs (https://www.php.net/manual/en/function.imagecreatefromwebp.php and https://www.php.net/manual/en/function.imagewebp.php), `false` should be returned on errors (similar to other functions of the `gd` extension), but actually all errors result in a `Fatal Error`. It doesn't look normal when trying to read an empty file or a file in the wrong format causes the program to stop. The problem seems to be related to a mega-patch that replaced `zend_error` with `zend_error_noreturn` almost everywhere. My patch fixes this behavior by switching from `zend_error_noerror` to `gd_error` (i.e. to `E_WARNING` level). All necessary memory cleanup is already in the code (as it was before the "zend_error_noreturn" patch).

Close GH-13774
2024-07-13 16:58:54 +01:00
Niels Dossche
361644b78d
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  ext/gd/tests/gh10614.phpt: skip if no PNG support
2024-07-10 19:51:11 +02:00
Michael Orlitzky
09957ab9a8
ext/gd/tests/gh10614.phpt: skip if no PNG support
This test uses imagecreatefrompng(), which won't be there if libgd was
built without PNG support.

Closes GH-14905.
2024-07-10 19:50:48 +02:00
Niels Dossche
7fe03e1a1b
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix parameter numbers for imagecolorset()
2024-06-05 18:04:53 +02:00
Giovanni Giacobbi
da769be7c9
Fix parameter numbers for imagecolorset()
This is the 8.2 & 8.3 version of GH-14477.
2024-06-05 18:01:59 +02:00
Gina Peter Banyard
b2c0db1f89
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  ext/readline: Fix [-Wcalloc-transposed-args] compiler warning
  ext/pdo_mysql: Fix [-Wcalloc-transposed-args] compiler warning
  ext/gd: Fix [-Wcalloc-transposed-args] compiler warning
  ext/ffi: Fix [-Wenum-int-mismatch] compiler warning
  ext/bcmath: Fix [-Wenum-int-mismatch] compiler warning
2024-05-21 12:21:46 +01:00
Gina Peter Banyard
3c45152798
ext/gd: Fix [-Wcalloc-transposed-args] compiler warning 2024-05-21 12:17:25 +01:00
Peter Kokot
f66696548b
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-12019: ext/gd/config.m4: don't forget GDLIB_CFLAGS in feature tests
2024-03-18 11:58:56 +01:00
Michael Orlitzky
00799320ec
Fix GH-12019: ext/gd/config.m4: don't forget GDLIB_CFLAGS in feature tests
In commit 85e5635a, 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 GH-12019
2024-03-18 11:57:20 +01:00
David Carlier
868257a3de Fix GH-13727: macro generating invalid call test prototypes fixes.
autoconf/libtool generating code to test features missed `void` for
C calls prototypes w/o arguments.
Note that specific changes related to libtool have to be upstreamed.

Co-authored-by: Peter Kokot <petk@php.net>

close GH-13732
2024-03-18 06:53:39 +00:00
Peter Kokot
d20f82669d Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix detection of image formats in system gd library
2024-02-26 14:00:08 +01:00
Michael Orlitzky
f732ab8b3e Fix detection of image formats in system gd library
- 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
2024-02-26 13:59:21 +01:00
Niels Dossche
b76ef301a0 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-10614: imagerotate will turn the picture all black, when rotated 90
2024-01-26 18:16:21 +01:00
Niels Dossche
f26dd1354b Fix GH-10614: imagerotate will turn the picture all black, when rotated 90
This is a backport of the upstream libgd PR that was recently committed
[1].

[1] https://github.com/libgd/libgd/pull/862

Closes GH-13246.
2024-01-26 18:15:52 +01:00
Niels Dossche
78986a6734 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-10344: imagettfbbox(): Could not find/open font UNC path
  Fix GH-13037: PharData incorrectly extracts zip file
2024-01-25 20:07:33 +01:00
Niels Dossche
4a48729438 Fix GH-10344: imagettfbbox(): Could not find/open font UNC path
libgd uses an incorrect absolute path check in gdft.c.
It checks if either the path starts with a '/' (only valid on Posix
btw), or whether it contains something of the form C:\ or C:/.
However, this overlooks the possibility of using UNC paths on Windows.
As we already do PHP-specific stuff with VCWD_ macros, use
IS_ABSOLUTE_PATH to check for an absolute path which will take into
account UNC paths as well.

Closes GH-13241.
2024-01-25 20:06:28 +01:00
David Carlier
cb97e7d8f3 Merge branch 'PHP-8.2' into PHP-8.3 2024-01-21 00:02:02 +00:00
David Carlier
8d4e177d82 ext/gd disable gh13082 test for travis.
The sample file is for little endian architectures.

Close GH-13208
2024-01-21 00:01:43 +00:00
Niels Dossche
7065fe3a88 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Follow-up fix for GH-13082
2024-01-13 18:02:25 +01:00