Commit Graph

781 Commits

Author SHA1 Message Date
Máté Kocsis
4e6fbb0a12
Promote warnings to exceptions in ext/gd
Closes GH-6023
2020-08-20 12:07:04 +02:00
Máté Kocsis
d94d426f60
Fix the default value handling of imagegif() 2020-07-31 10:01:08 +02:00
Máté Kocsis
ac0da090ae
Fix UNKNOWN default values in ext/mbstring and ext/gd
Closes GH-5598
2020-07-28 17:06:25 +02:00
Máté Kocsis
19bf66a9e4
Explode _php_image_output_ctx() into multiple functions
Closes GH-5844
2020-07-20 23:25:02 +02:00
Christoph M. Becker
340e2ead77 Export php_gd_libgdimageptr_from_zval_p()
Some extension may need to retrieve the `gdImagePtr` from an `GdImage`
object; thus, we export the respective function.  To not being forced
to include gd.h in php_gd.h, we use the opaque `struct gdImageStruct *`
as return type.

We also rename php_gd2.dll to php_gd.dll, since there's not really much
point in giving the DLL a version number, since there is no php_gd.dll
for years (if there ever has been).  Renaming, on the other hand,
matches the name on other systems (gd.so), and allows to actually use
`ADD_EXTENSION_DEP()`.
2020-07-11 19:33:20 +02:00
Máté Kocsis
d30cd7d7e7
Review the usage of apostrophes in error messages
Closes GH-5590
2020-07-10 21:05:28 +02:00
Max Semenik
2b5de6f839
Remove proto comments from C files
Closes GH-5758
2020-07-06 21:13:34 +02:00
Christoph M. Becker
92c4b06513 Use ZEND_UNREACHABLE() instead of ZEND_ASSERT(0)
Instead of marking unreachable code with `ZEND_ASSERT(0)`, we introduce
`ZEND_UNREACHABLE()`, so that MSVC which does not consider `assert(0)`
to mark unreachable code does no longer trigger C4715[1] warnings in
debug builds.  This may be useful for other compilers as well.

[1] <https://docs.microsoft.com/de-de/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4715?view=vs-2019>
2020-06-16 18:39:09 +02:00
George Peter Banyard
2f0dcf2ac2 Fix [-Wundef] warning in GD extension 2020-05-20 18:22:09 +02:00
Alex Dowad
8ddaf13ed3 Code tweaks: Remove unneeded semicolons 2020-04-29 23:17:40 +02:00
Remi Collet
ed179c2ef4 workaround typo in system libgd 2.3.0 2020-04-15 09:07:21 +02:00
Máté Kocsis
1f48feebb9
Improve some TypeError and ValueError messages
Closes GH-5377
2020-04-14 14:38:45 +02:00
Máté Kocsis
50765075db
Improve some ValueError messages
Closes GH-5340
2020-04-06 10:41:01 +02:00
Máté Kocsis
5322de1ba8
Generate functions entries from stubs for another set of extensions
Closes GH-5351
2020-04-05 00:59:44 +02:00
Máté Kocsis
01b266aac4
Improve error messages of various extensions
Closes GH-5278
2020-03-23 18:59:04 +01:00
Christoph M. Becker
03bd4333f6 Add imagegetinterpolation()
While `imagesetinterpolation()` is available as of PHP 5.5.0,
there is no according getter function, so users would have to track the
current interpolation method manually.

To remedy this, we introduce `imagegetinterpolation()` as thin wrapper
for `gdImageGetInterpolationMethod()` (which has been introduced with
libgd 2.1.1), and use `im->interpolation_id` as fallback for older
libgd.  Since our bundled libgd does not yet have this function, we add
it.

We also simplify the recently introduced bug79068.phpt, where it is
sufficient to check that the interpolation method has not been changed.
2020-01-14 18:25:27 +01:00
Christoph M. Becker
d83f89f076 Remove useless else branch
Passing `NULL` as `gdTransformAffineGetImage()`'s `src_area` is fine,
but in this case there's no need to calculate the `rect`, and since
`pRect` has already been initialized to `NULL`, we can remove the whole
else branch.
2020-01-06 08:54:57 +01:00
Máté Kocsis
aadd3aaed9
Use RETURN_THROWS() in various places 2020-01-03 21:10:24 +01:00
Máté Kocsis
9099dbd961
Use RETURN_THROWS() after zend_type_error() 2020-01-01 14:23:21 +01:00
Máté Kocsis
12ce73a5bb
Use RETURN_THROWS() after zend_value_error() 2019-12-31 16:58:15 +01:00
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