Commit Graph

190 Commits (master)

Author SHA1 Message Date
Pierre Joye 167ea1f4f0
Fix tests based on coverity reports (#819)
* Partial #818, unused arg

* Partial #818, init var

* partail #818, fix va_args usage

* partail #818, handle f* calls and avoid possible call to malloc with negative values

* partail #818, prevent double free

* partail #818, resource leak if test fail

* partail #818, null deref fix

* partail #818, avoid double free on fp failure

* Partial #818, fix error msg

* Partial #818, leak on error

* Partial #818, null deref

* Partial #818, avoid possible negative index on failure

* partial #818, does not free if we return if requested new size overflow

* partial #818, avoid double free, free where the alloc happened
2022-02-01 15:09:01 +07:00
Pierre Joye 3f872fc931
#792, document gdImageEllipse (#803) 2022-01-23 11:56:41 +07:00
Robert Hart ba14dec6ef
Fix out of bounds write im->alpha[im->transparent] (#785)
Since #737 gdImageColorTransparent does not correctly handle the case that im->transparent = -1
(which is the initial value and used to indicate no transparent colour has been set).

This leads to undefined behaviour via an out-of-bound write:
im->alpha[im->transparent] = gdAlphaOpaque;
(in practice I assume this merely overwrites an earlier struct member)

This can be triggered via loading a gif through gdImageCreateFromGifPtr

third_party/gd/source/gd.c:922:2: runtime error: index -1 out of bounds for type 'int [256]'
    #0 0x5629c034a839 in gdImageColorTransparent third_party/gd/source/gd.c:922:29
    #1 0x5629c034ebf0 in gdImageCreateFromGifCtx third_party/gd/source/gd_gif_in.c:328:4
    #2 0x5629c034f14f in gdImageCreateFromGifPtr third_party/gd/source/gd_gif_in.c:186:7

Fixes #784.
2021-10-09 11:40:45 -04:00
Tim Gates f7e57be725 docs: Fix a few typos
There are small typos in:
- examples/copyrotated.c
- src/gd.c
- src/gd.h
- src/gd_avif.c
- src/gd_nnquant.c
- src/gd_tga.c
- src/gd_topal.c
- src/wbmp.c
- tests/avif/compare_avif_to_png.c

Fixes:
- Should read `requires` rather than `reqiures`.
- Should read `of the` rather than `ofthe`.
- Should read `memory` rather than `memmory`.
- Should read `maximum` rather than `maxmum`.
- Should read `intersection` rather than `intertersection`.
- Should read `hypotenuse` rather than `hypothenus`.
- Should read `flexibility` rather than `flexibilty`.
- Should read `always` rather than `alwasy`.
- Should read `also` rather than `alos`.
2021-09-23 01:13:40 -04:00
Pierre Joye 1b3f6fbe94 Fix #410, document the exact behavior. It is not possible to change behavior at this point. 2021-08-27 07:00:11 +07:00
Pierre Joye b214ab236a
Merge pull request #737 from libgd/bug/405
Fix #405, -1 aims to reset the transparent color; refactor a bit; add test to existing test for -1
2021-08-27 01:24:00 +07:00
Michael Voříšek e8642aa54e
Fix gdAlphaMax limit typo 2021-08-26 18:59:12 +02:00
Pierre Joye 3a4d2127ef -1 resets the transparent color, return here. 2021-08-25 21:48:19 +07:00
Pierre Joye 67cc752b40 Fix #405, -1 aims to reset the transparent color; refactor a bit; add test to existing test for -1 2021-08-25 18:44:02 +07:00
Pierre Joye 49ecef1bf4 avoid case w/255.5+0.5 (kudos @cmb69) 2021-08-25 00:09:05 +07:00
Pierre Joye 8890f527b2 #661, restore correct clamping, fixing alpha artifacts (these ones are the most visible) 2021-08-24 23:08:09 +07:00
Mike Frysinger e1f02d2833 gd_intern: unify the min/max/clamp macros some more 2021-02-05 22:47:13 -05:00
Christoph M. Becker 9ed642764c Fix potential integer overflow detected by oss-fuzz 2020-08-24 17:03:07 +02:00
wilson chen ace7fd88dc
Fixed #169: update var type to hold bigger w&h for ellipse (#565)
Update var type to hold bigger w&h for ellipse. And add corresponding test cases.
2020-02-09 22:13:26 +08:00
Fábio Cabral Pacheco a93eac0e84 Fix potential NULL pointer dereference in gdImageClone() 2019-12-20 17:19:54 +01:00
Christoph M. Becker 21406b1a43 Fix #351: gdImageFilledArc() doesn't properly draw pies
The fix for PHP bug 43828[1] changed the algorithm from drawing filled
pies from drawing multiple triangles to drawing a single polygon.  Due
to quirks of the filled polygon drawing algorithm, we had to filter out
extraneous vertices.  This lead, however, to a bug regarding displaced
starting and ending points near 90° and 270° degrees, which we fix by
reinserting these vertices if they had been removed.

[1] <https://bugs.php.net/bug.php?id=43828>
2019-01-16 19:39:42 +01:00
Mike Frysinger a6dd3491a0 drop redundant color checks #456
These funcs were updated to always reject negative color values at
their start.  There's no need to keep these embedded negative checks.
2018-08-31 01:22:32 -04:00
Peter Kokot 01c59d840b Remove Git ident attributes
Git ident attributes were in most cases utilized with SVN and keywords
substitutions, where $Id$ were replaced with certain revision from the
repository. In Git this functionality is different. Each $Id$ needs to
be defined in .gitattributes file to be effective. This patch removes
unused and outdated attributes.
2018-06-27 02:04:37 +02:00
Mike Frysinger fd06f7f83c clean up trailing whitespace/newlines
This is preparation for adding some linting checks for new commits from
people.  Shouldn't be any functional changes here (tests still pass!).
2018-06-21 22:47:42 -04:00
Christoph M. Becker 1846f48e5f Fix #340: System frozen
gdImageCreate() doesn't check for oversized images and as such is prone
to DoS vulnerabilities. We fix that by applying the same overflow check
that is already in place for gdImageCreateTrueColor().

CVE-2016-9317
2016-12-13 16:02:19 +01:00
Christoph M. Becker 4ebdb483e4 Document gdImageCompare() 2016-10-06 18:28:46 +02:00
Christoph M. Becker b697bf74db Document cloning, copying, scaling and interpolation 2016-10-06 15:50:16 +02:00
Christoph M. Becker 65d40f5aa5 Fix #319: gdImageRotateInterpolated can have wrong background color
We backport the fix for <https://bugs.php.net/65070>, and also the fix for
<https://bugs.php.net/70976> which was introduced by fixing 65070.
2016-10-03 16:19:19 +02:00
Christoph M. Becker 9a43a7b3fd Test and document the effects (aka. alpha blending modes) 2016-10-02 18:29:28 +02:00
Christoph M. Becker ddddd0a2ba Improve anti-aliased drawing related docs 2016-10-02 11:54:36 +02:00
Christoph M. Becker 30453e94b2 Test and document filling behavior of self-intersecting polygons 2016-10-01 20:03:14 +02:00
Christoph M. Becker 7f7a7d8eca Fix #315: Single-point gdImageAALine() is invisible
We're treating a single-pointed gdImageAALine() as we treat vertical and
horizontal gdImageAALines(); namely, we draw it non-antialiased.
2016-10-01 01:43:59 +02:00
Christoph M. Becker c3cf674cb4 Fix overflow checks
We check for the proper sizeofs and add the additional sx*sy check for
gdImageCreate(), which serves as a quick check for totally oversized images.
2016-09-30 17:37:00 +02:00
Christoph M. Becker 0423df1131 Improve documentation 2016-09-15 23:36:49 +02:00
Christoph M. Becker 466d440002 Improve documentation 2016-09-15 14:59:21 +02:00
Christoph M. Becker 4b840e8216 Fix #300: gdImageClone() assigns res_y = res_x
We fix the obvious typo in gdImageClone(), add a regression test and improve
related documentation.
2016-09-12 23:59:51 +02:00
Christoph M. Becker 2fe471d5d4 Fix #299: Regression regarding gdImageRectangle() with gdImageSetThickness()
We remove the special casing for "point" rectangles with thick!=1 altogether,
and restrict the special casing for "line" rectangles to thick==1. We move
this necessary special casing (it fixes issue #172) towards the bottom of the
function like it is in PHP's bundled libgd.
2016-09-12 22:08:19 +02:00
Christoph M. Becker 4e8a94d36d Test and document gdImageRectangle
We're especially having a look at the point ordering issue, see
<https://github.com/libgd/libgd/issues/177>.
2016-09-12 14:33:17 +02:00
Christoph M. Becker 4933e316f4 Document image accessor macros 2016-09-11 17:54:14 +02:00
Christoph M. Becker c1804def24 Mark up code examples with (start|end code)
This makes the code better readable in the sources, and we get syntax
highlighting in the generated HTML wherever we want it (i.e. not necessarily
always as with `-hl all`).
2016-08-23 22:27:27 +02:00
Christoph M. Becker 4143073c88 Improve documentation of built-in fonts and their handling 2016-08-14 17:31:54 +02:00
Christoph M. Becker b0333689ef Document all BGD_DECLARE'd functions
We add only minimal documentation comments for now, but at least that lets
Natural Docs add the function prototypes to the documentation.
2016-07-20 21:24:48 +02:00
Christoph M. Becker b4f985a11d Merge branch 'pull-request/262' 2016-07-19 13:56:49 +02:00
Christoph M. Becker a212f60114 Merge branch 'pull-request/261' 2016-07-19 12:13:18 +02:00
Pierre Joye add4733944 Merge branch 'master' of github.com:libgd/libgd 2016-07-19 14:46:08 +07:00
Pierre Joye 0dd40abd6d fix possible OOB or OOM in gdImageScale, reported by Secunia (CVE 2016-6207) 2016-07-19 14:45:56 +07:00
Pierre Joye 118fc7098b php bug 72519, invalid color index for transparent color can lead to OOB 2016-07-19 14:38:26 +07:00
Christoph M. Becker e7e20d67d7 No pixel of a filled arc must ever be drawn multiple times
Otherwise we get artifacts regarding transparency. That happens with the
current implementation of gdImageFilledArc() unless gdChord or gdNoFill
are set. When gdPie is set, however, the filled arc is drawn in wedges,
which are polygons of three points, and so some overlap is natural.

To resolve the issue, we stick with the current algorithm of calculating the
wedges, but instead of drawing each polygon separately, we put the *relevant*
points in a large array, and draw a single polygon. That also is supposed to
improve the performance considerably.

Note that this modification will change the results when gdImageSetStyle()
or gdImageSetBrush() are used, but we believe that this modification is
also an improvement in this regard, even though it still might not make much
sense to use these functions with gdImageFilledArc().
2016-07-17 18:41:17 +02:00
Christoph M. Becker 9fd6021e12 Fix #252: gd_error() garbles variable arguments
Currently gd_error() forwards to gd_error_ex(). However, both functions
accept a variable number of arguments, and simply forwarding the va_list
isn't portable, see <http://c-faq.com/varargs/handoff.html>. This article
also describes the usual workaround, namely to let the second function
accept a va_list instead of variable number of arguments.

We do so by introducing a static helper, what does not affect API/ABI
compatibility.
2016-07-17 14:53:42 +02:00
Pierre Joye eafff87699 Merge branch 'GD-2.2'
* GD-2.2:
  fix CID 95837 duplicate code
  ensure null terminated string
  Fix #234: gdinterpolatedscale/gdTrivialResize is too slow
  ensure null terminated string
  Fix Coverity #95850: Structurally dead code
  Fix Coverity #102122: Unused value
  Fix Coverity #95850: Structurally dead code
  Fix Coverity #102122: Unused value
  Fix PHP bug #64641: imagefilledpolygon doesn't draw horizontal line
2016-06-21 12:17:46 +07:00
Pierre Joye f3b17253cb fix CID 95837 duplicate code 2016-06-21 12:17:26 +07:00
Christoph M. Becker b331c55f58 Fix PHP bug #64641: imagefilledpolygon doesn't draw horizontal line
As reported in <https://bugs.php.net/64641> 1-dimensional horizontal
filled polygons are not drawn at all. That is caused by the scanline
algorithm used for drawing filled polygons which skips the drawing of
horizontal edges, because that is normally not necessary. If, however,
the polygon consists of horizontal edges only, that obviously doesn't
work, so we add a special case handling.

(cherry picked from commit f9f10fa9d4)
2016-06-20 14:43:03 +02:00
Christoph M. Becker f9f10fa9d4 Fix PHP bug #64641: imagefilledpolygon doesn't draw horizontal line
As reported in <https://bugs.php.net/64641> 1-dimensional horizontal
filled polygons are not drawn at all. That is caused by the scanline
algorithm used for drawing filled polygons which skips the drawing of
horizontal edges, because that is normally not necessary. If, however,
the polygon consists of horizontal edges only, that obviously doesn't
work, so we add a special case handling.
2016-06-20 14:16:23 +02:00
Christoph M. Becker 0b9fe91679 Merge branch 'GD-2.2'
# resolved conflicts:
#	tests/gdimagerotate/bug00067.c
2016-06-15 17:55:38 +02:00
Christoph M. Becker c2b91dbce5 Fix #167: Styled thick horizontal lines are scrambled
Thick lines are drawn by gdImageFilledRectangle(), which iterates over
the x ordinate first (Z order) to apply the style pattern. While this works
fine for vertical and diagonal lines, it obviously fails for horizontal
lines, which have to be iterated over in N order.

To fix this bug, we introduce the helpers  gdImageFilled(H|V)Rectangle(),
which may be reused for other purposes as well.
2016-06-15 17:43:30 +02:00