Commit Graph

2295 Commits

Author SHA1 Message Date
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
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
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
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
2d05da2e94
Fix GH-16260: overflow/underflow on imagerotate degrees argument.
close GH-16264
2024-10-06 11:01:17 +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
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
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
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
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
3c45152798
ext/gd: Fix [-Wcalloc-transposed-args] compiler warning 2024-05-21 12:17:25 +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
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
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
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
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
df85c2556e Follow-up fix for GH-13082
The font_obj should actually be NULL initialised, not the font gd
pointer.

Closes GH-13139.
2024-01-13 18:01:59 +01:00
David Carlier
1e464e5b55 ext/gd: Fix GH-13082
Issue occur when compiling with recent clang releases (> 13) and
 with the '-Os' optimisation level, after using
`imageloadfont` which returns a proper GdFont class leads to
 a subtle bug when attempting to use via the imagefont* function.
2024-01-09 22:01:00 +00:00
Jakub Zelenka
6734880ef5
Fix bug #79945: Stream wrappers in imagecreatefrompng causes segfault
Closes GH-12696
2023-11-17 13:26:42 +00:00
Niels Dossche
6e0f4865bd Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix most external GD 2.3.3 compatibility
2023-07-06 21:40:20 +02:00
Michael Orlitzky
0aaad46c15 Fix most external GD 2.3.3 compatibility
* ext/gd/tests/bug45799.phpt: tweak to work with external gd.

The expected output from this test contains an extra newline with
gd-2.3.3 from the system (Gentoo). Adding a whitespace wildcard takes
care of it, and the test still passes with the bundled version of gd.

* ext/gd/tests: external gd-2.3.3 compatibility.

Support for the legacy "gd" image format was removed from gd-2.3.3
upstream:
  https://github.com/libgd/libgd/blob/master/CHANGELOG.md#233---2021-09-12

Several tests for the gd extension utilize that format, and naturally
fail when gd-2.3.3 from the system is used. This commit skips those
tests when the version of gd is at least 2.3.3.

* ext/gd/tests/bug73159.phpt: skip with external gd >= 2.3.3

This test uses the imagegd2() function to check that
  https://github.com/libgd/libgd/issues/289

is fixed. When an external gd without support for the "gd" format is
used, no error is thrown, but a nonsense result is printed: this is
normal. The corresponding upstream test is disabled in that situation;
it's not expected to work.

This commit skips the corresponding PHP test under the same
circumstances to fix a test failure with external gd >= 2.3.3.

* ext/gd/tests/bug73155.phpt: skip with external gd >= 2.3.3

This test uses the imagegd2() function to check that
  https://github.com/libgd/libgd/issues/309

is fixed. When an external gd without support for the "gd" format is
used, no error is thrown, but a nonsense result is printed: this is
normal. The corresponding upstream test is disabled in that situation;
it's not expected to work.

This commit skips the corresponding PHP test under the same
circumstances to fix a test failure with external gd >= 2.3.3.

* ext/gd/tests/bug73157.phpt: skip with external gd >= 2.3.3

This test ensures that the third (chunk_size) parameter to imagegd2()
is respected when a fourth parameter is also given. However, when an
external gd without support for the "gd" format is used, the call to
imagegd2() does not really work at all. It doesn't fail, but it
produces an "image" with a nonsense chunk size.

To avoid failures when an external gd >= 2.3.3 is used, we skip the
test entirely in that case.

* ext/gd/tests/bug77973.phpt: accept lowercase "Invalid"

This test fails with an external gd because the test expects "Invalid"
where upstream gd says "invalid". This commit tweaks the expected
output to accept an arbitrary character in the i/I position.

* ext/gd/tests/bug39780_extern.phpt: update for external gd-2.3.3.

Since there are no CI runs with external gd, I can only assume that
this test has fallen out-of-date due to changes in PHP itself. I've
tweaked the expected output (only slightly) so that the test passes
with both gd-2.3.2 and gd-2.3.3.

* ext/gd/tests/bug66356.phpt: update expected output for external gd.

Newer (external) versions of GD start their error messages with
lowercase characters, whereas this test is expecting them in
uppercase. A single-character wildcard now supports both formats.

* ext/gd/tests/imagegd_truecolor.phpt: skip with external gd >= 2.3.3.

This test uses the imagegd() function, but the "gd" format has been
disabled by default in upstream gd-2.3.3. We still get some kind of
image data back from the call to imagegd(), but its "signature",
"truecolor", and "size" no longer match the expected values. This
commit skips the test when an external gd >= 2.3.3 is used.

* ext/gd/tests/createfromwbmp2_extern.phpt: update for external gd-2.3.3.
* ext/gd/tests/libgd00086_extern.phpt: update for external gd-2.3.3.

Since there are no CI runs with external gd, I can only assume that
this test has fallen out-of-date due to changes in PHP itself. I've
tweaked the expected output (only slightly) so that the test passes
with both gd-2.3.2 and gd-2.3.3.

* ext/gd/tests/bug77272.phpt: update expected output for external gd.

Newer (external) versions of GD start their error messages with
lowercase characters, whereas this test is expecting them in
uppercase. A single-character wildcard now supports both formats.

* ext/gd/tests/bug77479.phpt: update for newer external gd.

This test fails with gd-2.3.3 (at least) due to minor capitalization
and whitespace issues. We add some wildcards to account for the
difference.

Closes GH-11257.
Closes GH-11262.
Closes GH-11264.
Closes GH-11280.
2023-07-06 21:39:40 +02:00
Michael Voříšek
411cd04541 Re-add some CTE functions that were removed from being CTE by a mistake
These functions were accidentally removed from being CTE in GH-7780.
This patch brings them back.

Closes GH-10768.
2023-03-07 20:30:11 +01:00
Ilija Tovilo
603367946b
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Add Windows GitHub actions build
2023-03-01 23:05:17 +01:00
Michael Voříšek
916b132ea0
Add Windows GitHub actions build
Closes GH-10664
2023-03-01 23:02:03 +01:00
Christoph M. Becker
797ee86170
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Update new test to use EXTENSIONS section instead of SKIPIF
2022-10-24 15:02:55 +02:00
Christoph M. Becker
b4fb66463b
Update new test to use EXTENSIONS section instead of SKIPIF 2022-10-24 15:02:05 +02:00
Stanislav Malyshev
dedaf40d21 Merge branch 'PHP-8.1' into PHP-8.2 2022-10-23 18:49:30 -06:00
Stanislav Malyshev
33e10cb1e0 Merge branch 'PHP-8.0' into PHP-8.1 2022-10-23 18:49:26 -06:00
Stanislav Malyshev
1d83a407d1 Merge branch 'PHP-7.4' into PHP-8.0 2022-10-23 18:49:21 -06:00
Christoph M. Becker
d50532be91 Fix #81739: OOB read due to insufficient validation in imageloadfont()
If we swap the byte order of the relevant header bytes, we need to make
sure again that the following multiplication does not overflow.
2022-10-23 18:41:48 -06:00
Bob Weinand
a01dd9feda Revert "Port all internally used classes to use default_object_handlers"
This reverts commit 94ee4f9834.

The commit was a bit too late to be included in PHP 8.2 RC1. Given it's a massive ABI break, we decide to postpone the change to PHP 8.3.
2022-09-14 11:13:23 +02:00
George Peter Banyard
1ad59b32c2 Update INI validator and displayers depending on INI type
Closes GH-9451
2022-09-06 10:33:34 +01:00
Bob Weinand
94ee4f9834 Port all internally used classes to use default_object_handlers
Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
2022-08-31 16:45:27 +02:00
Máté Kocsis
b4ec3e9bc0
Do not generate CONST_CS when registering constants (#9439) 2022-08-28 08:27:19 +02:00
Christoph M. Becker
b78c087b32
Fix typo (Paletter → Palette)
This also aligns the error message with upstream[1].

[1] <https://github.com/libgd/libgd/blob/gd-2.3.3/src/gd_webp.c#L182>

Closes GH-9414.
2022-08-24 13:40:16 +02:00
Máté Kocsis
056e968c54
Declare ext/gd constants in stubs (#9180) 2022-07-30 15:18:06 +02:00
Michael Voříšek
c756e978c4
Improve tests on 32bit
The watch_*.phpt test apparently no longer fail on 32bit, so we remove
the XFAIL conditions.  bug77269.phpt is practically identical to
bug77272.phpt, and there seems no particular reason to have an
additional test for libgd ≤ 2.2.5.

Closes GH-8448.
2022-06-29 14:04:40 +02:00
Christoph M. Becker
365537fd6d
Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix GH-8848: imagecopyresized() error refers to the wrong argument
2022-06-23 15:22:28 +02:00
Christoph M. Becker
bc8e52f651
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix GH-8848: imagecopyresized() error refers to the wrong argument
2022-06-23 15:22:09 +02:00
Christoph M. Becker
9405f43ba9
Fix GH-8848: imagecopyresized() error refers to the wrong argument
Closes GH-8849.
2022-06-23 15:20:49 +02:00
Christoph M. Becker
98a4ab2266
Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix imagecreatefromavif() memory leak
2022-06-17 17:31:48 +02:00
Christoph M. Becker
036bed01ce
Fix imagecreatefromavif() memory leak
This has been reported as https://github.com/libgd/libgd/issues/831.
We port the respective fix to our bundled libgd.

Closes GH-8812.
2022-06-17 17:30:57 +02:00
George Peter Banyard
8649cb8a96
Improve and fix stub return types (#8368) 2022-04-14 18:38:00 +01:00
Christoph M. Becker
0052af2a67
Merge branch 'PHP-8.1'
* PHP-8.1:
  Fixed libpng warning when loading interlaced images
2022-02-08 10:48:58 +01:00
Christoph M. Becker
4a630e67e9
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fixed libpng warning when loading interlaced images
2022-02-08 10:48:21 +01:00
Brett
1d48da6da5
Fixed libpng warning when loading interlaced images
We enable interlace transform when reading png.

Closes GH-8002.
2022-02-08 10:46:50 +01:00
Remi Collet
baeba4b0d7
Merge branch 'PHP-8.1'
* PHP-8.1:
  add missing conditions
  fix [-Wstrict-prototypes] build warnings in ext/gd
2021-11-25 13:20:37 +01:00