Commit Graph

2399 Commits

Author SHA1 Message Date
Christoph M. Becker
2d1c3825a8
Simplify WBMP imagecreatefromstring() detection (GH-16782)
According to the WBMP specification[1], the first field (type) of a
WBMP is a multi-byte integer, but only type `0` is supported.  Thus
there is no need to read a multi-byte integer.  The second field (fix
header) is a single byte; reading a multi-byte integer is not really
wrong, since the fix header field is laid out in a way which allows it
to be treated as such, but the check whether the MBI is greater than
or equal to zero is pretty useless, because negative values could only
be returned if overflow occurs (MBIs are unsigned).

So the only useful assumption we can make is that the first byte is
zero; we let `gdImageCreateFromWBMPCtx()` figure out the rest.

[1] <https://www.wapforum.org/what/technical/SPEC-WAESpec-19990524.pdf> section 6
2024-11-14 14:00:19 +01:00
David Carlier
ec05cd559b
Merge branch 'PHP-8.3' into PHP-8.4 2024-11-13 12:49:13 +00: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
d7e7e2b338
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16559: UBSan abort in ext/gd/libgd/gd_interpolation.c:1007
2024-10-23 20:10:04 +02: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
055b15f08c
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16427: Unchecked libavif return values
2024-10-14 13:54:52 +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
be370edbd7
Merge branch 'PHP-8.3' into PHP-8.4 2024-10-11 19:38:39 +01: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
7f1fd0646b
Merge branch 'PHP-8.3' into PHP-8.4 2024-10-07 13:05:41 +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
3caa5f8592
Merge branch 'PHP-8.3' into PHP-8.4 2024-10-06 11:02:12 +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
215c61f9c7
Merge branch 'PHP-8.3' into PHP-8.4 2024-10-05 11:34:59 +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
f89eb15f72
Port libgd/libgd/pull/711 (GH-16016)
Note that this is not actually security related[1], but still a
reasonable sanity check.

"If a function be advertised to return an error code in the event of
difficulties, thou shalt check for that code, yea, even though the
checks triple the size of thy code and produce aches in thy typing
fingers, for if thou thinkest it cannot happen to me, the gods shall
surely punish thee for thy arrogance." – Henry Spencer

[1] <https://github.com/libgd/libgd/issues/697#issuecomment-2369613187>
2024-09-24 13:58:31 +02:00
Christoph M. Becker
66060b1a9e
Support building ext/gd without libxpm on Windows (GH-15846)
For GD, libxpm is an optional dependency, and we should treat it as
such, i.e. if the library is not found, we build ext/gd without XPM
support.

This should also be done for other optional dependencies (like libjpeg),
but since we're close to PHP 8.4.0RC1, we postpone that.  However, wrt
libxpm[1] we're taking action immediately, so that we can ship builds
without XPM support, or at least custom builds without XPM support are
possible without modifying the sources.

[1] <https://news-web.php.net/php.internals/125502>
2024-09-12 12:29:18 +02:00
Peter Kokot
dfdec2d550
Autotools: Refactor PHP_TEST_BUILD checks (#15798)
- The libgd sanity check is there only to check whether all current
  linked libraries for the bundled libgd work together, otherwise it is
  probably even redundant a bit; this refactors it to a simpler
  AC_LINK_IFELSE check with default empty C program by Autoconf
- The IBM DB2 sanity check is simplified with AC_CHECK_FUNC instead
2024-09-08 21:05:30 +02:00
Peter Kokot
5ea6b044cd
Autotools: Fix gd extension -I flag for bundled libgd (#15786)
The ext_srcdir variable is at time of writing set only after calling the
PHP_NEW_EXTENSION. Other extensions also use @ext_srcdir@ template
placeholder for these cases. This fixes wrongly set include flag even
though build also works without libgd include flag.
2024-09-07 09:46:06 +02:00
DanielEScherzer
5dd0575698
Generated arginfo header files: combine preprocessor conditional blocks (#15736)
When functions' or class methods' 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.
2024-09-04 13:04:22 +02:00
DanielEScherzer
53cb89670c
Generated arginfo header files: remove empty zend_function_entry arrays (#15705)
When a class (or enum) has no methods, rather than using an array that only
contains `ZEND_FE_END`, use `NULL` for the functions. The implementation of
class registration for internal classes, `do_register_internal_class()` in
zend_API.c, already skips classes where the functions are `NULL`. By removing
these unneeded arrays, we can reduce the size of the header files, while also
removing an unneeded call to zend_register_functions() for each internal class
with no extra methods.
2024-09-03 23:19:53 +02:00
David Carlier
307565d577
ext/gd: porting gdImageClone to the bundled libgd version.
close GH-15640
2024-08-29 23:13:20 +01:00
Máté Kocsis
8d12f666ae
Fix registration of internal readonly child classes (#15459)
Currently, internal classes are registered with the following code:

INIT_CLASS_ENTRY(ce, "InternalClass", class_InternalClass_methods);
class_entry = zend_register_internal_class_ex(&ce, NULL);
class_entry->ce_flags |= ...;

This has worked well so far, except if InternalClass is readonly. It is because some inheritance checks are run by zend_register_internal_class_ex before ZEND_ACC_READONLY_CLASS is added to ce_flags.

The issue is fixed by adding a zend_register_internal_class_with_flags() zend API function that stubs can use from now on. This function makes sure to add the flags before running any checks. Since the new API is not available in lower PHP versions, gen_stub.php has to keep support for the existing API for PHP 8.3 and below.
2024-08-24 12:36:54 +02:00
Gina Peter Bnayard
5853cdb73d Use "must not" instead of "cannot" wording 2024-08-21 21:12:17 +01:00
Gina Peter Bnayard
e7c4d54d65 Use new helper function for "cannot be empty" ValueErrors 2024-08-21 21:12:17 +01:00
Peter Kokot
8c4f019cc6
Autotools: Sync CS in gd extension (#15364)
- Obsolete PHP_* variables checks removed (there was once the 'pdf'
  extension bundled in PHP that also had the same --with-*-dir configure
  options (3be17e3f26). When combined with
  the gd extension, options need to be executed conditionally; first one
  won), this is no longer relevant neither recommended practice to
  duplicate configure options inside the php-src context. Ideally,
  all configure options should be prefixed with an extension namespace
  --with-<extension-name>-<option> to be unique.
- AS_* macros used
2024-08-12 21:38:30 +02:00
Christoph M. Becker
9b41c8b1b5
Declare gdImageGetInterpolationMethod() for bundled GD (GH-15329)
When this function has been added to our bundled GD[1], it had been
overlooked to also declare it in gd.h, like it's done in libgd.  While
MSVC doesn't have any issues with this, clang reports an error.

[1] <03bd4333f6>
2024-08-10 16:57:48 +02:00
Peter Kokot
72fb00b644
Update gd extension preprocessor macros help texts (#15296)
PHP_GD_CHECK_FORMAT macro 2nd argument is changed from automatic
AC_DEFINE_UNQUOTED to manual action for easier usage.
2024-08-09 18:06:02 +02:00
Peter Kokot
11094d5f24
[skip ci] Fix typo in ext/gd 2024-08-05 16:23:38 +02:00
Peter Kokot
9049d86a78
[skip ci] Fix typo in ext/gd 2024-08-05 16:22:36 +02:00
Peter Kokot
8bfcbdc5ee
Fix HAVE_LIBGD usage (#15226)
When PHP gd extension uses the external system GD library, the
HAVE_LIBGD preprocessor macro gets defined in Autotools. On Windows it
was previously always defined when bundled library is used. This fixes
the usage and adds help texts.
2024-08-05 09:35:13 +02:00
Peter Kokot
dcdcb3cbfe
Autotools: Replace AC_MSG_ERROR with AC_MSG_FAILURE (#15209)
This replaces the AC_MSG_ERROR with AC_MSG_FAILURE, where appropriate.

The AC_MSG_ERROR outputs given message and exits the configure step. The
AC_MSG_FAILURE does the same but also automatically outputs additional
message "See 'config.log' for more details." which might help directing
the user where to look further.

The AC_MSG_ERROR is used for errors where current test step isn't logged
in the config.log and wouldn't make sense, and AC_MSG_FAILURE is mostly
used in cases of library checks, compilation tests, headers checked with
AC_CHECK_HEADER* and similar tests that are also logged in the
config.log.

AC_MSG_ERROR([Sanity check failed.]) output:

```
configure: error: Sanity check failed.
```

AC_MSG_FAILURE([Sanity check failed.]) output:

```
configure: error: in '/path/to/php-src':
configure: error: Sanity check failed.
See 'config.log' for more details
```
2024-08-04 07:36:37 +02:00
Peter Kokot
79af1b5280
Autotools: Remove unused variable FREETYPE2_FOUND
Follow-up of 19d8a6b771.
2024-07-30 11:25:24 +02:00
Peter Kokot
2b97c84d4c
Autotools: Quote PHP_CHECK_LIBRARY arguments (#15136)
This syncs the quotes across the PHP_CHECK_LIBRARY macro arguments.
2024-07-28 18:39:14 +02:00
Christoph M. Becker
6727f548b0
Port "gd2: use existing overflow2() rather than ad-hoc version" (#15090)
We port this modification[1] from libgd into our bundled libgd, because
the change makes sense, and we want the code bases to stay in sync as
close as possible.

We also apply a quick fix to the respective test.

[1] <f0a059be6c>
2024-07-24 14:18:36 +02:00
Peter Kokot
6cdff7573a
Autotools: Normalize ext/gd sources (#15086) 2024-07-24 01:52:51 +02:00
Peter Kokot
68ae477796
Autotools: Quote M4 arguments (#15033)
- PHP_ADD_INCLUDE
- PHP_EVAL_INCLINE
- PHP_EVAL_LIBLINE
2024-07-20 07:21:44 +02:00
Peter Kokot
0e2e8e0f13
Autotools: Quote all PHP_ADD_BUILD_DIR arguments (#14947)
- All arguments quoted for consistency
- m4_normalize used where list of directories becomes a bit simpler to
  read and see the diff
2024-07-14 16:58:43 +02:00
Christoph M. Becker
82fe4a2d48
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix skip condition of gh13082.phpt
2024-07-14 13:40:38 +02: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
a6d1844446
Merge branch 'PHP-8.3'
* PHP-8.3:
  Add test case for GH-13774
2024-07-14 12:48:22 +02:00