1
0
mirror of https://github.com/php/php-src.git synced 2026-04-30 03:33:17 +02:00
Commit Graph

2465 Commits

Author SHA1 Message Date
Peter Kokot 4d9fc506df Autotools, ext/gd: Ensure test program compiles without warnings (#19116)
In case compiler is configured in some strict way it might emit warnings
or even errors in the future if these aren't casted to void.
2025-07-13 17:17:14 +02:00
Peter Kokot d40b603856 ext/gd: Make BMP always available (#19115)
- When building with bundled libgd, it has support for BMP
- When building with external libgd, at least 2.1.0 is required, which
  has BMP support.
- The HAVE_GD_PNG moved to PHP_GD_PNG Autoconf macro as it is always
  required when building with bundled libgd.
2025-07-13 15:25:53 +02:00
Peter Kokot ba68cbefc5 ext/gd: Make TGA always available (#19105)
- When building with bundled libgd, it has support for TGA
- When building with external libgd, at least 2.1.0 is required, which
  has TGA support.
2025-07-13 11:45:44 +02:00
DanielEScherzer ddd33fd7e4 Generated arginfo headers: combine preprocessor conditional blocks (2) (#18667)
When global constants' or class constants' availability is based on some
preprocessor condition, the generated arginfo header files wrap the
declarations in the preprocessor `#if` conditional blocks, one per declaration,
even if they are in the same conditional block based on comments in the stub
file. Instead of having multiple conditional blocks one after the other with
the same condition, combine them into a single conditional block.
2025-06-22 14:35:28 -07:00
Tim Düsterhus 4c5a6b0e8d tree-wide: Remove stacktraces from tests testing throwing clones (#18748)
This is in preparation for the possible future transformation of `clone` into a
function call, but also meaningful on its own, since the purpose of the tests
is not to test the stack trace generation, but rather that an exception was
thrown. It also cleans up some unreachable code in the tests.
2025-06-03 20:08:47 +02:00
David CARLIER 2c3a2da48a ext/gd: array supplied to user optimisations. (#18366)
explictly allocate packed arrays when it applies.
2025-04-20 17:30:12 +01:00
David CARLIER 2e7df9e423 ext/gd: imagefilter* using overflow checks. (#18283)
Accept up to UINT_MAX * sizeof(int) colors.
2025-04-19 16:27:14 +01:00
Gina Peter Banyard 7a7b388401 ext/gd: Move FREETYPE defines into the ifdef 2025-04-05 18:12:21 +01:00
Gina Peter Banyard b647716199 ext/gd: Use RETURN_BOOL() where applicable
Instead of an if/else
2025-04-05 18:12:21 +01:00
Gina Peter Banyard be93f29f2f ext/gd: Reduce scope of variables 2025-04-05 18:12:21 +01:00
Gina Peter Banyard 9491c6850b ext/gd: Use uint32_t type instead of int type 2025-04-05 18:12:21 +01:00
Gina Peter Banyard 80ea28e918 ext/gd: Remove useless ext/standard header include 2025-04-05 18:12:21 +01:00
Gina Peter Banyard b535a54f5f ext/gd: Mark return types as true instead of bool 2025-04-05 18:12:21 +01:00
David Carlier abf6f8be71 Merge branch 'PHP-8.4' 2025-04-05 15:57:59 +01:00
David Carlier 471995c5f7 Merge branch 'PHP-8.3' into PHP-8.4 2025-04-05 15:57:26 +01:00
David Carlier fe8dffef5d Fixed GH-18243: imagettftext underflow/overflow on size argument.
close GH-18245
2025-04-05 15:56:45 +01:00
Gina Peter Banyard bda9ff8338 ext/gd: Flip size and nb arguments for safe_emalloc()
The size should be the second one
2025-04-04 15:12:06 +01:00
David Carlier 18102ec708 Merge branch 'PHP-8.4' 2025-03-28 17:31:50 +00:00
David Carlier 3a5c87f964 Merge branch 'PHP-8.3' into PHP-8.4 2025-03-28 17:31:13 +00: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 ea86442857 Merge branch 'PHP-8.4' 2025-03-07 18:08:30 +00:00
David Carlier bc55177832 Merge branch 'PHP-8.3' into PHP-8.4 2025-03-07 18:07:48 +00:00
David Carlier 07ceadf7d9 Fix GH-17984: gd calls with array arguments.
close GH-17985
2025-03-07 18:07:14 +00:00
David Carlier 06101224b4 Merge branch 'PHP-8.4' 2025-02-24 07:15:08 +00:00
David Carlier fc73da57f4 Merge branch 'PHP-8.3' into PHP-8.4 2025-02-24 07:14:56 +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 18df1e4783 ext/gd create gd object with zend_object_alloc (#17823)
while at it, fix build warning "wrong" calloc arguments order
2025-02-16 00:05:37 +00:00
David Carlier 77d748617a Merge branch 'PHP-8.4' 2025-02-14 15:29:32 +00:00
David Carlier ed18fd073a Merge branch 'PHP-8.3' into PHP-8.4 2025-02-14 15:28:48 +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
David Carlier 65a20d5a09 Merge branch 'PHP-8.4' 2025-02-05 19:41:16 +00:00
David Carlier dc7b661a60 Fix GH-17703: imagescale both width and heigh set with negative values.
Throwing a ValueError in this particular case.

close GH-17708
2025-02-05 19:39:51 +00:00
Christoph M. Becker c1f7b87fb1 Fix MSVC C4267 warnings in gd.c (GH-17680)
These warnings are about conversion from `size_t` to a smaller type[1],
and in this case because `gdIOCtx` works with `int` lengths.  Two of
these warnings are harmless, and we resolve them by using `size_t` in
the first place, and adding a cast (plus an assertion), respectively.

The others actually hint at potential issues when reading image data
with more than `INT_MAX` bytes; we catch that upfront, and throw a
`ValueError` and a warning, respectively.

[1] <https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4267>
2025-02-03 21:02:15 +01:00
Christoph M. Becker efcdcd7bde Drop NetWare support from bundled libgd (GH-17596)
This has been removed from upstream years ago[1], and PHP generally
dropped NetWare support even earlier.

[1] <https://github.com/libgd/libgd/commit/e6bb110663722836ba1e6986b27252bc4402a33c>
[2] <https://externals.io/message/96838>
2025-01-27 20:00:34 +01:00
Christoph M. Becker 5890761ef9 Overhaul GD test helpers and affected tests (GH-17309)
* Use type declarations instead of doc-block annotations

* Inline the terrible get_rgb() function

* Always traverse pixels in Z order

libgd stores the pixel as an array of rows, so we should use row-major-
order traversal to improve caching.

* Add assertions to avoid misuse of the functions

The assertion regarding the image dimensions won't break any tests, and
we had it already as a comment.

However, asserting that the images are truecolor images is important
for `calc_image_dissimilarity()` which otherwise would calculate
nonsense, and not unreasonable for `test_image_equals_image()` which
otherwise is overspecified (for our purposes, it doesn't matter which
palette entry a pixel refers to, but rather whether the actual colors
referred by a palette color match).

Since the truecolor assertions break two tests, we fix these by
converting to truecolor.  That should likely be backported to lower
branches.

* Drop implicit conversion to truecolor

Conversion to truecolor is a relatively expensive operation, and as
such should not be implicit; instead test authors are encouraged to use
truecolor images in the first place where possible, or to even find
better ways to verify expectations than doing a full image comparison.

* Merge similarity.inc into func.inc

There is no particular reason to have a separate file for similarity
comparisons.

* Simplify bug43475.phpt and bug64641.phpt

`calc_image_dissimilarity()` calculates the sum of the euclidean
distance of the RGB channels of all pixels.  The euclidean distance is
either zero or greater than or equal to one (but never in ]0, 1[).  The
sum of these values also has this property, so it doesn't make sense to
check for less than 1e-5.  Thus we just call `test_image_equals_file()`
instead.

* Replace calc_image_dissimilarity() with the well-known mse()

`calc_image_dissimilarity()` has the drawback that it did sum up the
pixel differences, so for large images the result could be way larger
than for small images.  It also has the drawback that it likely is not
as well understood as the mean squared error.  Thus we replace it with
the latter, and calculate the mean squared error of the individual RGB
channels (to be precise).  The result is always in range 0..255**2 what
makes reasoning about thresholds easier.
2025-01-25 19:48:38 +01:00
Christoph M. Becker f698c62361 Fix bug 64823: ZTS GD fails to to find system TrueType font
First, the `$fontfile` parameter actually supports a semicolon
delimited list of fonts (as documented[1]); thus passing the full
string to `VCWD_REALPATH()` or `php_check_open_basedir()` makes no
sense; we could pass the individual parts, but …

Second, libgd uses an elaborate font detection.  There is a hard-
coded `DEFAULT_PATH` which can be overridden by the environment
variable `GDFONTPATH`.  Semantics are like the `PATH` environment
variable.  If `DEFAULT_PATH` was still exposed (it is no longer as of
libgd 2.1.0[2]), we could take that into account, but …

External libgd can be configured with font-config support, so font
aliases and even lookup patterns are supported.  There is no way to
cater to that upfront.

Thus, we no longer interfere with libgd's font lookup.  Checking the
realpath was already doubtful (we didn't even use the resolved path).
Lifting the open_basedir restriction is a bit more delicate, but the
manual still states that open_basedir would not apply, and more
relevant, not much harm can be done, because libgd only passes the
found font to `FT_New_Face()` which likely fails for any non font files
without any error which could reveal sensitive information.  And the
font file is never written.

It should be noted that this solves lookup of system fonts, does not
change the behavior for absolute font paths, but still does not resolve
issues with relative paths to font files in ZTS environments using
external libgd (our bundled libgd has a workaround for that).  This
particular issue cannot be solved, so users of ZTS builds still need to
add `realpath(.)` to the `GDFONTPATH` as documented in the manual (or
pass absolute paths as `$fontfile`).

[1] <https://www.php.net/imagettftext>
[2] <https://github.com/libgd/libgd/commit/2a921c80fbdd1d684f32bf763c26e024052314e6>

Closes GH-17366.
2025-01-25 19:27:05 +01:00
Christoph M. Becker aa76127d01 Address more Clang warnings (GH-17506)
We prefer clean solutions (such as declaring the proper type in the
first place, or introducing a portable format specifier) where easily
possible, but resort to casts otherwise.

We also port https://github.com/libgd/libgd/commit/f1480ab14bd5e2e4b4d83d8f3e64e786aa810637.
2025-01-21 20:05:29 +01:00
Christoph M. Becker 0f40e62ca7 Fix bug 68629: Transparent artifacts when using imagerotate
We port the respective upstream fix[1], which dropped the special cased
implementations of fixed-point arithmetic rotation in favor of the
generic implementation.

We also port follow-up upstream fixes[2][3].

[1] <https://github.com/libgd/libgd/commit/bd6d2e101f6f1df106d1cd2e2dc8058a5538109b>
[2] <https://github.com/libgd/libgd/commit/6d21d304295731d67db324dc3bf4630a69ebc5d6>
[3] <https://github.com/libgd/libgd/commit/9df878a4006130f3b5c8ee6e1f5ce9e8e6c9db07>

Closes GH-17375.
2025-01-09 13:19:25 +01:00
Christoph M. Becker 757faee9ec Merge branch 'PHP-8.4'
* PHP-8.4:
  Add support for reading GIFs without colormap
2025-01-09 12:07:03 +01:00
Christoph M. Becker 38365a44d0 Add support for reading GIFs without colormap
Cf. <https://github.com/libgd/libgd/commit/fc38677e8005c24db891b84d3e84df7a199c979c>.

Closes GH-17364.
2025-01-09 12:06:24 +01:00
Christoph M. Becker 2c49f52b0d Port "improve _gdImageFillTiled() internal function" (GH-17356)
This improvement was done for libgd 2.1.0[1], and the erroneous
calculation has been fixed as of libgd 2.2.0[2].

While we're at it we also add the overflow checks of external libgd;
these are not really necessary, since `.sx * .sy` overflow was already
prevented when the image has been created, and since we're using
`safe_emalloc()` the `struct seg` overflow is also prevented.  It
should be noted that `overflow2()` prevents `int` overflow, while
`safe_emalloc()` prevents `size_t` overflow, so the former is more
restrictive.  For parity with external libgd, this still appears to be
a good thing.

[1] <https://github.com/libgd/libgd/commit/86a5debede97ded92d644c3e06964c299e1e0810>
[2] <https://github.com/libgd/libgd/commit/e87ec88e1c4db664baf2c42e7fccf3f9dc53f0a6>
2025-01-07 01:23:05 +01:00
Christoph M. Becker e4df0cbe1c Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix libgd 223: gdImageRotateGeneric() does not properly interpolate
2025-01-06 20:39:14 +01:00
Christoph M. Becker 12e4ee492b Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix libgd 223: gdImageRotateGeneric() does not properly interpolate
2025-01-06 20:38:34 +01: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. <https://github.com/libgd/libgd/commit/2b26be874d0c0987c4906a40ef8f0e8fee04ae8f>.

Closes GH-17380.
2025-01-06 20:37:23 +01:00
Christoph M. Becker f5aa69a5fc Port "merged and expanded settings from gd.h and gdft.c" (GH-17367)
This commit[1] and the related part of the Netware removal[2] move the
related definitions out of gd.h, and bring some updates.

[1] <https://github.com/libgd/libgd/commit/2a921c80fbdd1d684f32bf763c26e024052314e6>
[2] <https://github.com/libgd/libgd/commit/e6bb110663722836ba1e6986b27252bc4402a33c>
2025-01-06 15:01:50 +01:00
Christoph M. Becker cc84d271ea Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-17373: imagefttext() ignores clipping rect for palette images
2025-01-06 14:59:38 +01:00
Christoph M. Becker 61dcfc4c9a Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-17373: imagefttext() ignores clipping rect for palette images
2025-01-06 14:59:03 +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 a3ef48c265 Port "move pixelate filter to gd_filter.c" (sync with upstream) (GH-17361)
Cf. <https://github.com/libgd/libgd/commit/0f0894a7dd5c74cb9824f5c297569434c0f5b12e>.
2025-01-05 11:24:24 +01:00