Commit graph

861 commits

Author SHA1 Message Date
Máté Kocsis
d9ac1ca8de
Use ZEND_THROWS() during ZPP in the GD, gettext, GMP, and hash extensions 2019-12-31 00:21:38 +01:00
Dmitry Stogov
62826e95d2 Merge branch 'PHP-7.4'
* PHP-7.4:
  Call zend_unregister_ini_entries() when unload extension loaded through dl() without MSHUTDOWN callback. Extensions with MSHUTDOWN should use UNREGISTER_INI_ENTRIES().
2019-12-09 15:07:39 +03:00
Dmitry Stogov
92c23e1fd3 Call zend_unregister_ini_entries() when unload extension loaded through dl() without MSHUTDOWN callback.
Extensions with MSHUTDOWN should use UNREGISTER_INI_ENTRIES().
2019-12-09 15:05:24 +03:00
Christoph M. Becker
2de79f0855 Make the $num_points parameter of php_imagepolygon optional
That parameter is mostly useless in practise, and likely has been
directly ported from the underlying `gdImagePolygon()` and friends,
which require that parameter since the number of elements of the point
array would otherwise be unknown.  Typical usages of `imagepolygon()`,
`imageopenpolygon()` and `imagefilledpolygon()` pass `count($points)/2`
or hard-code this value as literal.  Since explicitly specifying this
parameter is annoying and error-prone, we offer the possibility to omit
it, in which case the `$points` array must have an even number of
elements, and the number of points is calculated as `count($points)/2`.
2019-11-15 09:41:10 +01:00
Christoph M. Becker
7d96dcac2c Fix #55005: imagepolygon num_points requirement
We actually have to check `$num_points` instead of `2*count($points)`,
because the latter may be greater than the former, but not all elements
of `$points` are guaranteed to be used.  This allowed to pass arrays
with excess elements to draw polygons with less than three vertices.

While the current implementation of `gdImagePolygon()` and friends
would allow us to draw monogons and digons, we don't allow that
anymore, because the respective drawing primitives work slightly
different (e.g. drawing lines support anti-aliasing, but drawing
general polygons does not).

To minimize the BC break, we do not fix this longstanding issue for PHP
7, but target PHP 8 only.
2019-11-02 14:05:01 +01:00
Christoph M. Becker
88bab00199 Remove unused code
These are left-overs from image2wbmp(), which has already been removed.
2019-11-02 00:10:46 +01:00
Christoph M. Becker
a601d519aa Just return after throwing a ValueError 2019-09-30 16:40:56 +02:00
Mark
8aad466c42 Convert GD Resources to objects 2019-09-30 15:14:02 +02:00
Gabriel Caruso
5d6e923d46
Remove mention of PHP major version in Copyright headers
Closes GH-4732.
2019-09-25 14:51:43 +02:00
Christoph M. Becker
4f4074328c Prefer ValueError over Error in GD
Cf. <https://github.com/php/php-src/pull/4682>.
2019-09-10 12:37:42 +02:00
Peter Cowburn
a43679632b raise ValueError from imagecreate/imagecreatetruecolor
Raise a ValueError instead of a plain Error when calling imagecreate()
or imagecreatetruecolor() with too big or small values for the width or
height arguments.
2019-09-09 21:06:00 +01:00
Mark
5af8361060 Warnings to Errors: imagesetstyle 2019-09-04 15:21:59 +02:00
Mark
4a1f0eb9d3 Warnings to errors in imageaffinematrix*() 2019-09-04 15:18:07 +02:00
Mark
06a3dd536d Warnings to errors in imagecrop(auto) 2019-09-04 15:12:04 +02:00
Mark
d1f9ab11b3 Warnings to errors imageconvolution 2019-09-04 12:42:17 +02:00
Mark
34865f54e7 Warnings become errors for imagepolygon et al 2019-09-04 12:35:48 +02:00
Mark
87dbb32246 Negative checks for gamma 2019-09-04 12:31:01 +02:00
Mark
af8ecb39ae Warnings for image colour range check now throw exceptions 2019-09-04 12:27:08 +02:00
Mark
6c6c109e24 Warnings to errors for imagecreatefromgd2part
We also delete tests which were duplicates of a completely unrelated
test.
2019-09-04 12:22:27 +02:00
Mark
6a05e42459 Warnings to Errors imagetruecolortopalette 2019-09-04 12:14:34 +02:00
Mark
fde52e8a2c Warnings to Errors imagecreate(truecolor)
We also add a test helper which we will be using for other GD functions
as well.
2019-09-04 12:09:07 +02:00
Christoph M. Becker
4281b1378e Don't explicitly set return value on ZPP/ZFR failure
Failing `zend_parse_parameters()` and `zend_fetch_resource()` throw as
of PHP 8.0.0, so explicitly setting a return value is useless, and also
slightly confusing.
2019-08-12 14:42:26 +02:00
Nikita Popov
429378d78d Remove some misleading RETURN_FALSE
These functions throw, so they can't return false.

This is just a subset...
2019-08-12 10:05:36 +02:00
Christoph M. Becker
f30501b172 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix parameter order
2019-08-11 16:18:44 +02:00
Christoph M. Becker
9818f863c3 Fix parameter order
`imagecopymerge()` and `imagecopymergegray()` expect the destination
image first, not the other way round.
2019-08-11 16:16:39 +02:00
Christoph M. Becker
f273204011 Merge branch 'PHP-7.4'
* PHP-7.4:
  Extend color component range checks
2019-08-11 15:23:23 +02:00
Christoph M. Becker
092571c1cb Extend color component range checks
We also check for alpha components to be within range, and we add yet
missing range checks for other functions as well.
2019-08-11 15:21:05 +02:00
Christoph M. Becker
c90a27387e Add GD function stubs 2019-08-11 13:17:24 +02:00
Nikita Popov
a1e2c8870e Merge branch 'PHP-7.4' 2019-07-22 17:26:01 +02:00
Nikita Popov
d59aac58b3 Report errors from stream read and write operations
The php_stream_read() and php_stream_write() functions now return
an ssize_t value, with negative results indicating failure. Functions
like fread() and fwrite() will return false in that case.

As a special case, EWOULDBLOCK and EAGAIN on non-blocking streams
should not be regarded as error conditions, and be reported as
successful zero-length reads/writes instead. The handling of EINTR
remains unclear and is internally inconsistent (e.g. some code-paths
will automatically retry on EINTR, while some won't).

I'm landing this now to make sure the stream wrapper ops API changes
make it into 7.4 -- however, if the user-facing changes turn out to
be problematic we have the option of clamping negative returns to
zero in php_stream_read() and php_stream_write() to restore the
old behavior in a relatively non-intrusive manner.
2019-07-22 17:17:28 +02:00
Remi Collet
92d6720dcf Merge branch 'PHP-7.4'
* PHP-7.4:
  cleanup gd build with system libgd - drop need to use libpng with system libgd - drop need to use libjpeg with system libgd - drop need to use libXpm with system libgd - drop need to use libfreetype with system libgd - improve configure comments
2019-07-22 16:14:36 +02:00
Remi Collet
31d85b8417 cleanup gd build with system libgd - drop need to use libpng with system libgd - drop need to use libjpeg with system libgd - drop need to use libXpm with system libgd - drop need to use libfreetype with system libgd - improve configure comments 2019-07-22 16:14:19 +02:00
Christoph M. Becker
ebe91a0066 Merge branch 'PHP-7.4'
* PHP-7.4:
  Drop superfluous ENABLE_GD_TTF
2019-07-22 12:01:58 +02:00
Christoph M. Becker
d3d3404db7 Drop superfluous ENABLE_GD_TTF
If we `HAVE_LIBFREETYPE`, we define `ENABLE_GD_TTF` if it is not
defined.  Therefore we can check for `HAVE_LIBFREETYPE` in the first
place.
2019-07-22 12:01:24 +02:00
Nikita Popov
e36118a5c5 Merge branch 'PHP-7.4' 2019-07-16 12:20:21 +02:00
Nikita Popov
290e520c03 Use ZEND_HASH_FOREACH APIs in a few more places 2019-07-16 12:20:16 +02:00
Christoph M. Becker
611c57eaf7 Merge branch 'PHP-7.4'
* PHP-7.4:
  Properly shut down font cache mutex
2019-06-21 16:01:28 +02:00
Christoph M. Becker
eec5d2a25f Properly shut down font cache mutex
Since the font cache mutex in set up in MINIT, we have to shut it down
in MSHUTDOWN.
2019-06-21 16:00:47 +02:00
Christoph M. Becker
7469d572f2 Merge branch 'PHP-7.4'
* PHP-7.4:
  Support TGA reading
2019-06-20 23:41:23 +02:00
Christoph M. Becker
81fd113506 Support TGA reading
We add PHP bindings for libgd's features to read TGA files, which are
available as of libgd 2.1.0.

As PHP's bundled libgd doesn't yet include the respective features of the
external libgd, we add these.

Since TGA has no easily recognizable file signature, we don't add TGA
support for imagecreatefromstring() or getimagesize() and friends.
2019-06-20 23:40:51 +02:00
Nikita Popov
681136212f Merge branch 'PHP-7.4' 2019-06-20 10:16:31 +02:00
Nikita Popov
4488475a3e imagecolorallocate(): Check that RGB components are in-range
Instead of letting them bleed over into other components.
2019-06-20 10:09:54 +02:00
Nikita Popov
6ae9c10534 Merge branch 'PHP-7.4' 2019-06-19 16:36:29 +02:00
Nikita Popov
88b603768f imageloadfont: Perform overflow check before calculation
Instead of afterwards...
2019-06-19 15:50:52 +02:00
Christoph M. Becker
692673f6a4 Merge branch 'PHP-7.4'
* PHP-7.4:
  Add BMP support to PHP info
2019-06-13 13:07:30 +02:00
Christoph M. Becker
3c5bb06536 Add BMP support to PHP info 2019-06-13 13:07:01 +02:00
twosee
63171d88f2 Add do...while(0) for RETURN_* and ZVAL_* APIs
Closes GH-4255.
2019-06-12 16:17:16 +02:00
Nikita Popov
a31f46421d Allow exceptions in __toString()
RFC: https://wiki.php.net/rfc/tostring_exceptions

And convert some object to string conversion related recoverable
fatal errors into Error exceptions.

Improve exception safety of internal code performing string
conversions.
2019-06-05 14:25:07 +02:00
Kalle Sommer Nielsen
569e338104 Merge branch 'PHP-7.4'
* PHP-7.4:
  Implemented the gdScatter filter I wrote almost 10 years ago
2019-05-10 02:24:01 +03:00
Kalle Sommer Nielsen
bcd11a1dfb Implemented the gdScatter filter I wrote almost 10 years ago
This filter is available as of libgd 2.1.0 which is our bare minimum for
external compilation of ext/gd.

The scatter filter works by iterating over all pixels in the image and
shifting them randomly based on two modifier (`plus` and `sub`) values:

dest_x = (int)(x + ((rand() % (plus - sub)) + sub));
dest_y = (int)(y + ((rand() % (plus - sub)) + sub));

Additionally the scatter filter also supports by only shifting pixels where
the current pixel being iterated is one or more colors, allowing the scatter
filter to only effect solid colors in part of an image.

Note, due to the nature of randomness and implementation, pixels who were
shifted ahead of iteration will be shifted once more and therefore the
bottom right of an image may contain a slight scatter effect due to this.
2019-05-10 02:23:40 +03:00