Commit Graph

1237 Commits (master)

Author SHA1 Message Date
Mike Frysinger 9fa3abd2e6 gif: fix out-of-bounds read w/corrupted lzw data
oss-fuzz pointed out:
gd_gif_in.c:605:16: runtime error: index 5595 out of bounds for type 'int [4096]'

Add some bounds checking on each code that we read from the file.
2018-01-26 01:57:52 -05:00
Mike Frysinger a8f1d5cab0 wbmp: getmbi: use unsigned int to avoid undefined shift behavior
oss-fuzz pointed out:
wbmp.c:48:14: runtime error: left shift of 253751679 by 7 places cannot be represented in type 'int'

See previous commit for more details.
2018-01-25 23:25:56 -05:00
Mike Frysinger 772d0107a6 gdGetIntLSB: use unsigned int to avoid undefined shift behavior
oss-fuzz pointed out:
gd_io.c:174:10: runtime error: left shift of 255 by 24 places cannot be represented in type 'int'

See previous commit for more details.
2018-01-25 23:18:56 -05:00
Mike Frysinger 24d352576c gdGetInt: use unsigned int to avoid undefined shift behavior
oss-fuzz pointed out:
gd_io.c:139:14: runtime error: left shift of 199 by 24 places cannot be represented in type 'int'

Switch the temp var we use here to unsigned to avoid that.  We do an
unsigned int to a signed int at the end which is undefined, but since
compilers don't seem to mind that, we won't care just yet.  It also
makes the code match gdGetIntLSB behavior.
2018-01-25 23:02:32 -05:00
Mike Frysinger fdbd8df682 add underscores around attributes
We use __attribute__ instead of attribute everywhere to avoid namespace
issues, so make sure we use the same style for the attribute options too.
2018-01-25 21:51:03 -05:00
Tim D. Smith f3dc031df7 Make ReadOK fail on short reads 2018-01-24 21:05:41 -05:00
Mike Frysinger dd76e8fcf2 generate & install gdlib.pc for cmake builds too #164 2018-01-10 01:56:10 -05:00
Mike Frysinger 60016a4426 include snprintf.c in the dist tarball
The cmake files refer to it for older Windows builds.  Fixes #416.
2018-01-10 00:59:34 -05:00
Christoph M. Becker 712d9ec181 Fix #411: gd_gd.c format documentation appears to be incorrect
The palette headers always consist of 256 palette entries, and if
`\377\377\377\377` is given for the transparency, that means that there
is no transparent color.
2017-09-07 15:27:18 +02:00
Christoph M. Becker c39fa1e03c Document GD 1.x image format 2017-09-03 15:50:42 +02:00
Christoph M. Becker 5176856eae Fix potential memory leak in gdImageStringFTEx()
Of course, we have to free all allocated resources before returning.

Reported by shqking <shqking@gmail.com> to security@libgd.org.
2017-08-29 16:47:24 +02:00
Christoph M. Becker 3b8a69cfe5 Merge branch 'pull-request/346' 2017-08-27 17:45:20 +02:00
Christoph M. Becker 2207e3c88a Fix #381: libgd double-free vulnerability
The issue is that `gdImagePngCtxEx` (which is called by `gdImagePngPtr`
and the other PNG output functions to do the real work) does not return
whether it succeeded or failed, so this is not checked in
`gdImagePngPtr` and the function wrongly assumes everything is okay,
which is not, in this case, because the palette image contains no
palette entries.

We can't change the signature of `gdImagePngCtxEx` for API
compatibility reasons, so we introduce the static helper
`_gdImagePngCtxEx` which returns success respective failure, so
`gdImagePngPtr` and `gdImagePngPtrEx` can check the return value. We
leave it solely to libpng for now to report warnings regarding the
failing write.

CVE-2017-6362
2017-08-27 17:18:34 +02:00
Christoph M. Becker a7a7ece43c Fix #386: gdImageGrayScale() may produce colors
We have to make sure to avoid alpha-blending issues by explicitly
switching to `gdEffectReplace` and to restore the old value afterwards.

We also document the algorithm used by `gdImageGrayScale()` and note
its limitations regarding palette images.
2017-08-27 12:57:03 +02:00
Christoph M. Becker 1c090dc01e Fix #406: webpng -i removes the transparent color
We have to initialize `trans_col` to the value that guards the call to
`gdImageColorTransparent()`. To avoid confusion, we replace the magic
numbers with a macro.
2017-08-25 12:13:19 +02:00
Christoph M. Becker 880c9f6def Back-port fix for PHP bug 75111
Although libgd is not really affected by this issue, because contrary
to PHP's bundled libgd it does not allow to read from negative offsets,
we consider it still a bug that `dynamicSeek()` does not behave like
`fileSeek()` with regard to negative positions.

As this behavior cannot be probed from outside, we omit the regression
test.
2017-08-24 14:32:20 +02:00
Christoph M. Becker c613bc1698 Close #339: Fix unitialized memory read vulnerability in GIF reading
The stack allocated color map buffers were not zeroed before usage, and
so undefined palette indexes could cause information leakage.

This issue has been reported by Matviy Kotoniy to security@libgd.org in
<CAKm_7a-AO++B6cXYWM_DtycPENG5WNWK7NSEvQ5OmZziMY_JyA@mail.gmail.com>.
2017-08-10 18:31:29 +02:00
Galik 3385b9aebf Truetype font drawing functions now take `const` strings (#400)
The following API functions now accept the font names and the text to be
printed as `const char*` rater than `char*`. This makes the functions
much more `C++` friendly.

gdImageStringFT();
gdImageStringTTF();
gdImageStringFTEx();

Other functions/types affected:

typeed struct fontkey_t;

any2eucjp();
gdTcl_UtfToUniChar();
DetectKanjiCode();
do_convert();
do_check_and_conv();
2017-07-29 11:24:32 -04:00
Mike Frysinger 660abbeb96 fix some unused variable errors when built w/out png 2017-02-15 10:57:24 -05:00
Christoph M. Becker e65415d91c Fix Coverity #155476: potential resource leak
If the reading of GD2 images fails due to a truncated file, we have to
make sure that all resources are freed. We do so by going to `fail`
instead of bailing out early.

This is a minor issue, though, as GD2 isn't recommended for production
use at all.
2017-01-30 12:41:04 +01:00
Christoph M. Becker acc11040cd Fix Coverity #155475: Failure to restore alphaBlendingFlag
Actually, there is no need to change the alphaBlendingFlag in the first
place, if the buffer allocation fails, so we move the allocation
attempt up.
2017-01-30 12:29:02 +01:00
Christoph M. Becker b4d153ba96 Fix and reenable optimized support for reading 1 bps TIFFs
Due to #82 the optimized support for reading 1 bps TIFF files (black &
white) had been disabled. Tony Lew already pointed out a fix in #88.

Furthermore, there was the following missing and improper error handling:
* TIFFReadScanline() returns -1 on error, not 0
* the result of TIFFReadTile() hasn't been checked
* in case of failure of these functions, the error had not been
  propagated

We fix this, and re-enable direct support for 1 bps TIFFs, which is
more memory efficient than the general RGBA support. We also make sure
not to hit any not yet implemented code path.
2017-01-25 23:28:23 +01:00
Christoph M. Becker bffad4da3c Add a test for reading X10 bitmap files
We also improve the related documentation, which didn't mention yet
which X bitmap formats are supported.
2017-01-21 16:56:12 +01:00
Christoph M. Becker 082c544483 Fix #109: XBM reading fails with printed error
When calculating the number of required bytes of an XBM image, we have
to take the line padding into account.
2017-01-20 22:49:28 +01:00
Christoph M. Becker 381e89de16 Fix build issue regarding INT_MAX
For portability gd_gd2.c needs to include <limits.h>.

(cherry picked from commit c9b601a658a79e6ea2aad29fbf60ca6e24ccef1e)
2017-01-19 01:10:40 +01:00
Christoph M. Becker 55ac28a293 Fix #357: 2.2.4: Segfault in test suite.
We make sure to never pass a negative `int` as argument to a `size_t`
parameter.
2017-01-19 01:02:58 +01:00
Christoph M. Becker 1f57639f04 Remove unused functions
gdImageRotate() and gdImageRotate45() are neither used by GD nor
exported, so we remove them.
2017-01-10 18:57:24 +01:00
Christoph M. Becker 69d2fd2c59 Fix #354: Signed Integer Overflow gd_io.c
GD2 stores the number of horizontal and vertical chunks as words (i.e. 2
byte unsigned). These values are multiplied and assigned to an int when
reading the image, what can cause integer overflows. We have to avoid
that, and also make sure that either chunk count is actually greater
than zero. If illegal chunk counts are detected, we bail out from
reading the image.
2016-12-17 17:38:02 +01: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 58b6dde319 Fix OOB reads of the TGA decompression buffer
It is possible to craft TGA files which will overflow the decompression
buffer, but not the image's bitmap. Therefore we also have to check for
potential decompression buffer overflows.

This issue had been reported by Ibrahim El-Sayed to security@libgd.org;
a modified case exposing an off-by-one error of the first patch had been
provided by Konrad Beckmann.

This commit is an amendment to commit fb0e0cce, so we use CVE-2016-6906
as well.
2016-12-13 15:51:51 +01:00
Christoph M. Becker fe9ed49daf Fix DOS vulnerability in gdImageCreateFromGd2Ctx()
We must not pretend that there are image data if there are none. Instead
we fail reading the image file gracefully.
2016-12-13 15:33:42 +01:00
Christoph M. Becker 60bfb401ad Fix potential unsigned underflow
No need to decrease `u`, so we don't do it. While we're at it, we also factor
out the overflow check of the loop, what improves performance and readability.

This issue has been reported by Stefan Esser to security@libgd.org.
2016-12-13 15:16:03 +01:00
Christoph M. Becker a49feeae76 Fix double-free in gdImageWebPtr()
The issue is that gdImageWebpCtx() (which is called by gdImageWebpPtr() and
the other WebP output functions to do the real work) does not return whether
it succeeded or failed, so this is not checked in gdImageWebpPtr() and the
function wrongly assumes everything is okay, which is not, in this case,
because there is a size limitation for WebP, namely that the width and
height must by less than 16383.

We can't change the signature of gdImageWebpCtx() for API compatibility
reasons, so we introduce the static helper _gdImageWebpCtx() which returns
success respective failure, so gdImageWebpPtr() and gdImageWebpPtrEx() can
check the return value. We leave it solely to libwebp for now to report
warnings regarding the failing write.

This issue had been reported by Ibrahim El-Sayed to security@libgd.org.

CVE-2016-6912
2016-12-13 14:40:03 +01:00
Christoph M. Becker 4859d69e07 Fix invalid read in gdImageCreateFromTiffPtr()
tiff_invalid_read.tiff is corrupt, and causes an invalid read in
gdImageCreateFromTiffPtr(), but not in gdImageCreateFromTiff(). The culprit
is dynamicGetbuf(), which doesn't check for out-of-bound reads. In this case,
dynamicGetbuf() is called with a negative dp->pos, but also positive buffer
overflows have to be handled, in which case 0 has to be returned (cf. commit
75e29a9).

Fixing dynamicGetbuf() exhibits that the corrupt TIFF would still create
the image, because the return value of TIFFReadRGBAImage() is not checked.
We do that, and let createFromTiffRgba() fail if TIFFReadRGBAImage() fails.

This issue had been reported by Ibrahim El-Sayed to security@libgd.org.

CVE-2016-6911
2016-12-13 13:55:48 +01:00
Christoph M. Becker fb0e0cce0b Fix OOB reads of the TGA decompression buffer
It is possible to craft TGA files which will overflow the decompression
buffer, but not the image's bitmap. Therefore we augment the check for the
bitmap's overflow with a check for the buffer's overflow.

This issue had been reported by Ibrahim El-Sayed to security@libgd.org.

CVE-2016-6906
2016-12-13 13:31:05 +01:00
Christoph M. Becker fea55903ee Fix #338: Fatal and normal libjpeg/ibpng errors not distinguishable
libgd clients need to be able to distinguish between fatal and
"extremely fatal" libjpeg and libpng errors, because in the former case
execution can proceed, but in the latter case libgd calls exit().
Therefore we report fatal errors as GD_WARNING.
2016-11-16 18:10:29 +01:00
Mike Frysinger 5ebbd50cff cmake: add soname info to libgd.so
Pull out the library versioning info out of configure and into a common
script that both cmake & autotools can run.  This way we have a single
source of truth for the versioning info.
2016-11-10 09:09:14 -05:00
Christoph M. Becker 939d49a3a9 Fix #68: gif: buffer underflow reported by AddressSanitizer
The buffer underflow happens at the start of the bitstream and after
each clear code, where the wrap-around is actually unnecessary. To
avoid the buffer underflow we simply initialize scd->last_byte to 2,
instead of adding further control logic to skip the relevant
assignments altogether.

We do not add a regression test, because the buffer underflow could
only be detected with ASAN or a similar memory-checker (or debugging),
and it happens for all proper GIFs anyway, so other tests (such as
tests/gif/gif_im2im) already exhibited the behavior.
2016-10-15 19:00:57 +02:00
Christoph M. Becker 5311087193 Avoid potentially dangerous signed to unsigned conversion
We make sure to never pass a negative `rlen` as size to memcpy(). See
also <https://bugs.php.net/bug.php?id=73280>.

Patch provided by Emmanuel Law.
2016-10-12 11:15:32 +02:00
Christoph M. Becker ca2b34e1f8 Fix #329: GD_BILINEAR_FIXED gdImageScale() can cause black border
We're passing `pixel1` as default color to `getPixelOverflow*()` for
pixels which may be outside the valid bounds. `pixel1` is supposed to
be always valid due to the fixed arithmetic's round towards zero
behavior.
2016-10-10 12:45:13 +02:00
Christoph M. Becker 77c8d359bb Fix #330: Integer overflow in gdImageScaleBilinearPalette()
The color components are supposed to be in range 0..255, so we must not
cast them to `signed char`, what can be the default for `char`.
2016-10-10 11:05:27 +02:00
Christoph M. Becker b6b44d962d Document that gdImageScale() does not yet support GD_WEIGHTED4 2016-10-09 18:21:31 +02:00
Christoph M. Becker 0c0cd18aff Revert "Fix #328: gdImageScale() with GD_WEIGHTED4 always returns NULL"
This reverts commit 0809c9f644.
2016-10-09 18:17:03 +02:00
Christoph M. Becker 0809c9f644 Fix #328: gdImageScale() with GD_WEIGHTED4 always returns NULL
Actually, there is no special case implementation for GD_WEIGHTED4
interpolation yet, so we must not pretend there would.
2016-10-09 16:25:07 +02:00
Christoph M. Becker 1f3f82d901 Document cropping stuff 2016-10-09 12:46:31 +02:00
Christoph M. Becker 1458f8765c Support writing lossless WebP
Lossless WebP is a rather interesting alternative to PNG, and already
supported by `gdImageCreateFromWebp*()`, so we add support for
`gdImageWebp*()`, too.

We can stick with the existing API, using the quality parameter to
request lossless encoding if it is set to `gdWebpLossless`, which we
define to `PHP_INT` (to avoid adding a new dependency to gd.h, we hard-
code the value – we're assuming `sizeof(int)==4` anyway).
2016-10-09 00:47:05 +02: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 1b6564cdc8 Fix 321: Null pointer dereferences in gdImageRotateInterpolated
We let gdImageRotateInterpolated() fail early, if `src` is NULL.
2016-10-06 14:20:24 +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 ddf3b493f1 Fix color quantization documentation 2016-10-03 10:26:42 +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 d6d2dec0fb Test and document gdImageFlip*() 2016-10-02 14:36:09 +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 3e8b5c5ee2 Test and document some filter functions 2016-09-27 13:34:18 +02:00
Christoph M. Becker 0ef4df3e16 Fix GD2 format documentation
We must not forget the chunk headers.
2016-09-24 14:02:11 +02:00
Christoph M. Becker bb1998a16e Fix #309: gdImageGd2() writes wrong chunk sizes on boundaries 2016-09-23 18:29:52 +02:00
Christoph M. Becker 25e18ebce8 Improve documentation of truecolor to palette conversion 2016-09-21 14:14:27 +02:00
Christoph M. Becker 408ea5e5c3 Fix #307: GD_QUANT_NEUQUANT fails to unset trueColor flag
Before we copy the quantized palette image onto the original image, we have
to mark the latter as palette image. We also have to free the allocated
truecolor pixels; free_truecolor_image_data() does all that for us.
2016-09-21 12:42:49 +02:00
Christoph M. Becker 096f843e85 Revert "Fix #307: GD_QUANT_NEUQUANT fails to unset trueColor flag"
This reverts commit a74909b9a4.
2016-09-21 00:29:22 +02:00
Christoph M. Becker a74909b9a4 Fix #307: GD_QUANT_NEUQUANT fails to unset trueColor flag
We must unset the trueColor image after converting it; gdImageCopy() wont't
(rightly) do that for us.
2016-09-21 00:15:47 +02:00
Christoph M. Becker 40bec0f38f Merge branch 'pull-request/296' 2016-09-16 10:54:34 +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 8ca157f67e No, we don't HAVE_BUNDLED_GD
This is obviously a relict of PHP's bundled libgd, which we should remove.
And actually, the #ifdef isn't necessary anymore for PHP's bundled libgd
either, because it supports gdImageAlphaBlending().
2016-09-14 20:10:29 +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 a59523038d Fix #297: gdImageCrop() converts palette image to truecolor image
When just cropping an image, we want to stick with the same image type.
2016-09-11 16:17:49 +02:00
trylab 2806adfdc2 Fix integer overflow in gdImageWebpCtx
Integer overflow can be happened in expression gdImageSX(im) * 4 *
gdImageSY(im). It could lead to heap buffer overflow in the following
code. This issue has been reported to the PHP Bug Tracking System. The
proof-of-concept file will be supplied some days later. This issue was
discovered by Ke Liu of Tencent's Xuanwu LAB.
2016-09-06 18:35:32 +08:00
Christoph M. Becker b95197edee Fix fontlist doc 2016-09-04 18:45:46 +02:00
Christoph M. Becker 7a3a2da3d9 Fix potential build error
Without JPEG support `in` is unused, and causes a build failure due to
`-Werror`.
2016-09-03 19:12:58 +02:00
Christoph M. Becker 24b4550fa8 Fix PHP bug #67325: imagetruecolortopalette: white is duplicated in palette
gdImageTrueColorToPalette() is sometimes wasteful by putting multiple white
color entries into the palette. This is caused by an obvious typo, where
to avoid a division by zero when `total` is zero, `count` is checked instead
of `total`.

We fix this issue, to improve the quality of the color quantization.
2016-09-03 17:48:03 +02:00
Christoph M. Becker 0bd7ec0560 Fix use-after-free vulnerability
Of course, we must not free `text` before we're finished with it.

As this issue affects master only, it is not a security issue.
2016-08-27 16:08:38 +02:00
Christoph M. Becker 59d077aeab Fix build failure for --without-fontconfig
If fontconfig support is disabled, the static functions font_pattern() and
useFontConfig() are never used. This can lead to build errors, and does so
with the current default settings `-Wall -Werror`. Therefore we ensure that
these functions are not compiled when they are not needed.
2016-08-27 11:49:40 +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 4778a8a946 Document gdft.c and gdfx.c
We also remove the respective comments from the *private* gdfx.h.
2016-08-23 21:35:32 +02:00
Christoph M. Becker 4f8e26f2a4 Fix #290: TGA RLE decoding is broken
We make it work only, for now. Actually, it doesn't make sense that
`oTga::bitmap` is an `int *` as we're storing only bytes there. If this
will be changed, we can even get rid of the `conversion_buffer` in
`read_image_tga` altogether, and read the image data into the
`decompression_buffer` (if RLE'd) or the `tga->bitmap` (if uncompressed)
directly.
2016-08-16 14:27:23 +02:00
Christoph M. Becker 88302603ef Fix unnecessary non NULL checks
Coverity rightly complains that `tmp_img` is checked for being `!= NULL`,
*after* it has been dereferenced[1]. Actually, the `NULL` check is not
necessary at all. To be on the safe side, we assert that `src != NULL` when
`gdImageScaleTwoPass()` has been called.

[1] <https://scan8.coverity.com/reports.htm#v30161/p11047/fileInstanceId=12793299&defectInstanceId=4423754>
2016-08-15 18:16:12 +02:00
Christoph M. Becker 09090c1256 Fix #289: Passing unrecognized formats to gdImageGd2 results in corrupted files
We must not apply the format correction twice for truecolor images.
2016-08-15 17:49:40 +02:00
Christoph M. Becker 5ee392d6e8 First stab at documenting the GD and GD2 image formats 2016-08-14 20:01:19 +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 9a3bd7077e Group the supported image formats in the menu of the docs
To do so we have to add Menu.txt to the project, but we can ignore
Languages.txt and Topics.txt, at least for now.
2016-08-14 16:11:05 +02:00
Mike Frysinger b7a01fe6e3 gdft: fix build when freetype is disabled
In file included from gdft.c:20:0:
entities.h:17:4: error: 'entities' defined but not used [-Werror=unused-variable]

gdft.c:1741:15: error: 'font_path' defined but not used [-Werror=unused-function]
 static char * font_path(char **fontpath, char *name_list)
2016-08-10 13:35:08 +08:00
Mike Frysinger 9d26490ed1 gd2: fix build when zlib is disabled
gd_gd2.c: In function 'gdImageGd2Ptr':
gd_gd2.c:1122:1: error: control reaches end of non-void function [-Werror=return-type]
2016-08-10 13:26:20 +08:00
Christoph M. Becker 9b8ae7e221 Fix #280: gdImageWebpEx() `quantization` parameter is a misnomer
We therefore change the name to `quality`.
2016-08-05 12:53:18 +02:00
Christoph M. Becker 4d9459678f Actually document gdFree() 2016-08-03 16:16:29 +02:00
Christoph M. Becker 5cd8336c26 Publish all gdImageCreateFromWebp*() functions and gdImageWebpCtx()
These have already been BGD_DECLARE'd in gd.h, so we also do so in the actual
sources. While we're at it, we also add some documentation.
2016-08-03 15:41:17 +02:00
Christoph M. Becker 92991d1630 Fix issue #276: Sometimes pixels are missing when storing images as BMPs
That happens only when RLE is applied. The culprit is in compress_row(),
where the rightmost pixels which wouldn't be run-length encoded were
ignored; instead we now add them uncompressed to the `row`.
2016-07-24 23:45:28 +02:00
Christoph M. Becker cc6d20b36f Revert "Fix issue #276: Sometimes pixels are missing when storing images as BMPs"
This reverts commit b355a7f392, because
the test case is broken and has to be fixed.
2016-07-24 23:19:19 +02:00
Christoph M. Becker b355a7f392 Fix issue #276: Sometimes pixels are missing when storing images as BMPs
That happens only when RLE is applied. The culprit is in compress_row(),
where the rightmost pixels which wouldn't be run-length encoded were
ignored; instead we now add them uncompressed to the `row`.
2016-07-24 23:02:33 +02:00
Christoph M. Becker 497ba7fc3c Fix issue #275: gdImageBmpCtx() may segfault for non-seekable contexts
We must not check for `compression == 1`, but more generally for
`compression`. Furthermore we improve the related documentation.
2016-07-24 15:37:28 +02:00
Christoph M. Becker 28440a4087 Remove superfluous if statement 2016-07-23 19:16:14 +02:00
Christoph M. Becker f101380bc6 Fix copy&paste error in gdImageScaleBicubicFixed() 2016-07-23 17:51:21 +02:00
Mike Frysinger d304360411 build: sync libgd source lists
The cmake build was missing gd_color_match.c which meant the library
didn't export the gdImageColorMatch function.  Sync the two lists in
the autotools and cmake files to make this easier to check.  Listing
header files in autotools source lists isn't a problem.
2016-07-22 18:12:48 +05:30
Mike Frysinger c78ae3e4d6 cmake: add visibility support #260
This makes sure we don't export symbols in libgd.so that we shouldn't.

We now assume that, if you're using gcc, you're using at least version
3.3 as that's the first to support the visibility attribute.  We can
wait to see if anyone complains before worrying about older ones.
2016-07-22 18:12:48 +05:30
Mike Frysinger 5090a9ebf7 cmake: allow static libs to be disabled
The standard behavior in distros nowadays is to build shared libs and
omit static libs.  Split the build knobs in cmake to support this.  It
also matches what's available with the autotools build.
2016-07-22 15:09:04 +05:30
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 8b7e76dd37 Fix typo introduced in 0dd1706 2016-07-20 13:27:30 +02:00
Pierre Joye 0dd1706c14 possible null deref 2016-07-20 17:00:16 +07:00
Pierre Joye e29a140290 revert, color is unsigned, <0 never happened 2016-07-20 16:40:17 +07:00
Pierre Joye bb16ba0297 Merge branch 'master' of github.com:libgd/libgd 2016-07-20 16:19:44 +07:00
Pierre Joye 7dfd79bbca improve color check for CropThreshold 2016-07-20 16:19:12 +07: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 b263053eac Merge branch 'master' of github.com:libgd/libgd 2016-07-19 17:07:17 +07:00
Pierre Joye 7a28c23589 fix possible OOB or OOM in gdImageScale, reported by Secunia (CVE 2016-6207) 2016-07-19 17:05:54 +07:00
Christoph M. Becker 71f2ff370e Fix #264: TGA warning coverity
We fix the unintended sign extension issue #150385 by declaring encoded_pixels
as int, and the logical vs. bitwise operator issue #150382 by using the
proper operator.
2016-07-19 11:41:46 +02:00
Pierre Joye f60ec7a546 fix possible OOB or OOM in gdImageScale, reported by Secunia (CVE 2016-6207) 2016-07-19 16:30:52 +07:00
Pierre Joye ff9113c80a fix possible OOB or OOM in gdImageScale, reported by Secunia (CVE 2016-6207) 2016-07-19 15:57:08 +07:00
Pierre Joye d325888a9f fix possible OOB or OOM in gdImageScale, reported by Secunia (CVE 2016-6207) 2016-07-19 15:25:47 +07: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 d818ff9391 Merge branch 'master' of github.com:libgd/libgd 2016-07-19 14:38:59 +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
Ondřej Surý ff0234f4da Proper fix for #248 2016-07-15 09:43:45 +02:00
Ondřej Surý 981060efd6 bug #248, fix Out-Of-Bounds Read in read_image_tga 2016-07-14 10:39:41 +02:00
Christoph M. Becker cb1a0b7e54 Unsupported TGA bpp/alphabit combinations should error gracefully
Currently, only 24bpp without alphabits and 32bpp with 8 alphabits are
really supported. All other combinations will be rejected with a warning.
2016-07-13 00:43:10 +02:00
Christoph M. Becker 076e0d19d7 Revert "Unsupported TGA bpp/alphabit combinations should error gracefully"
This reverts commit 10ef1dca63.

There are build errors, so we revert for now.
2016-07-12 22:09:13 +02:00
Christoph M. Becker 10ef1dca63 Unsupported TGA bpp/alphabit combinations should error gracefully
Currently, only 24bpp without alphabits and 32bpp with 8 alphabits are
really supported. All other combinations will be rejected with a warning.
2016-07-12 20:46:33 +02:00
Ondřej Surý ead349e998 Fix #247, A read out-of-bands was found in the parsing of TGA files (CVE-2016-6132) 2016-07-12 16:11:51 +02:00
Mike Frysinger 973cac8f3f Merge pull request #246 from khalidalqassabi/raqm
Add complex text layout support
2016-06-30 08:35:55 -04:00
Khalid Alqassabi 1dbccb737c Add complex text layout support
This pull request (based on Asma's works) adds support for languages that require [complex text
layout](https://en.wikipedia.org/wiki/Complex_text_layout).

We are using [libraqm](https://github.com/HOST-Oman/libraqm), a small source
code-only library that wraps FriBidi (for bidirectional text support) and
HarfBuzz (for text shaping), and does proper BiDi and script itemization.

The CTL support is enabled by default but can be disabled at compiling time,
and we provide a fallback function that uses your original code without CTL
support.
2016-06-30 13:19:25 +04:00
Pierre Joye a6a0e7feab fix php bug 72339 (CVE-2016-5766), Integer Overflow in _gd2GetHeader() resulting in heap overflow. Sync with php's sync 2016-06-29 09:36:26 +07:00
Pierre Joye aba3db8ba1 fix php bug 72339 (CVE-2016-5766), Integer Overflow in _gd2GetHeader() resulting in heap overflow 2016-06-28 16:23:42 +07:00
Pierre Joye a0f9f8f7bd fix php 72494, CID 149753, color is unsigned int, remove useless <0 comparison 2016-06-27 11:43:34 +07:00
Pierre Joye 1ccfe21e14 fix php 72494, invalid color index not handled, can lead to crash 2016-06-27 11:41:40 +07:00
Pierre Joye 89520807f1 Merge branch 'GD-2.2'
* GD-2.2:
  fix CID 95839
  update
2016-06-24 09:45:08 +07:00
Pierre Joye 68a9c79e7c fix CID 95839 2016-06-24 09:44:44 +07:00
Pierre Joye 7a661d2de6 update 2016-06-24 09:15:38 +07:00
Pierre Joye 81888a70b0 update 2016-06-24 09:13:12 +07:00
Pierre Joye 3ac1d291e3 Merge branch 'GD-2.2'
* GD-2.2:
  fix CID 95839, fix logic and avoid duplicate code (and confusion)
  Add coverity status
2016-06-21 14:40:19 +07:00
Pierre Joye 9d4d314701 fix CID 95839, fix logic and avoid duplicate code (and confusion) 2016-06-21 14:00:32 +07:00
Pierre Joye a280b5c38d Merge branch 'GD-2.2'
* GD-2.2:
  fix CID 95837 duplicate code
2016-06-21 12:26:20 +07:00
Pierre Joye fa1e9b7612 fix CID 95837 duplicate code 2016-06-21 12:24:35 +07: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
Pierre Joye 9f28c16ee0 ensure null terminated string 2016-06-21 10:40:06 +07:00
Pierre Joye 8757e32181 ensure null terminated string 2016-06-21 10:30:15 +07:00
Pierre Joye 292103e750 Merge branch 'master' of github.com:libgd/libgd 2016-06-21 10:21:01 +07:00
Christoph M. Becker cdbb81a07a Fix Coverity #95850: Structurally dead code
We slightly refactor the code to not use an else clause at all, what also
makes the code cleaner.

(cherry picked from commit 832c1ba791)
2016-06-21 00:28:36 +02:00
Christoph M. Becker 5eeb608db2 Fix Coverity #102122: Unused value
Apparently, that's a leftover from the "mode_mono fix from Giuliano Pochini".

(cherry picked from commit 327bf3d8b1)
2016-06-21 00:28:35 +02:00
Christoph M. Becker 832c1ba791 Fix Coverity #95850: Structurally dead code
We slightly refactor the code to not use an else clause at all, what also
makes the code cleaner.
2016-06-21 00:23:02 +02:00
Christoph M. Becker 327bf3d8b1 Fix Coverity #102122: Unused value
Apparently, that's a leftover from the "mode_mono fix from Giuliano Pochini".
2016-06-21 00:18:46 +02: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
Pierre Joye d74f3521df Merge branch 'GD-2.2'
* GD-2.2:
  fix coverity 95857, given the underlying functions, risks to actually have a string overflow seems not possible. However this little safety check costs nothing and puts us on a 100% side.
2016-06-20 14:38:07 +07:00
Pierre Joye 6e72c35d81 fix coverity 95857, given the underlying functions, risks to actually have a string overflow seems not possible. However this little safety check costs nothing and puts us on a 100% side. 2016-06-20 14:37:38 +07:00
Pierre Joye a61d9f3600 Merge branch 'GD-2.2'
* GD-2.2:
  fix coverity CID 149461, check return value, return error
2016-06-20 10:09:54 +07:00
Pierre Joye 7c64cb9697 fix coverity CID 149461, check return value, return error 2016-06-20 10:09:35 +07:00
Pierre Joye cf6243fb5a Merge branch 'GD-2.2'
* GD-2.2:
  fix coverity CID 95855, missing break
  fix coverity CID 95865: bail out nicely on too long font name
2016-06-20 09:43:21 +07:00
Pierre Joye 9afd8c0737 fix coverity CID 95855, missing break 2016-06-20 09:42:16 +07:00
Pierre Joye 77055bc404 fix coverity CID 95865: bail out nicely on too long font name 2016-06-20 09:35:56 +07:00
Pierre Joye a01ebfaf86 Merge branch 'GD-2.2'
* GD-2.2:
  fix coverity CID 95841, should not happen but in case libpng adds special cases we will be covered here.
2016-06-20 09:20:00 +07:00
Pierre Joye 2b7c36d074 fix coverity CID 95841, should not happen but in case libpng adds special cases we will be covered here. 2016-06-20 09:19:17 +07:00
Pierre Joye 64a6371bd4 Merge branch 'GD-2.2'
* GD-2.2:
  fix covererity CID 95842, duplicate code
2016-06-20 09:13:10 +07:00
Pierre Joye bb4f6cca59 fix covererity CID 95842, duplicate code 2016-06-20 09:12:31 +07:00
Pierre Joye b6281cd6a9 Merge branch 'GD-2.2'
* GD-2.2:
  we need unsigned char storage here, not unsigned char *, aka allocate the right size
2016-06-19 16:00:02 +07:00
Pierre Joye bcc3d53a55 we need unsigned char storage here, not unsigned char *, aka allocate the right size 2016-06-19 15:59:43 +07:00
Pierre Joye ec74decf20 Merge branch 'GD-2.2'
* GD-2.2:
  let use unsigned here, the result is used as index anyway
2016-06-19 15:51:42 +07:00
Pierre Joye 78cd8a618d let use unsigned here, the result is used as index anyway 2016-06-19 15:51:21 +07:00
Pierre Joye 1e12a7eca0 Merge branch 'GD-2.2'
* GD-2.2:
  return if ctx creation failed
  clean up unused vars
  return if ctx creation failed
2016-06-19 15:41:13 +07:00
Pierre Joye 878569fd41 return if ctx creation failed 2016-06-19 15:40:53 +07:00
Pierre Joye 8fd40005ad return if ctx creation failed 2016-06-19 15:24:37 +07:00
Pierre Joye 85af454e89 Merge branch 'GD-2.2'
* GD-2.2:
  simplify, no need to allocate color here as it always true color
2016-06-19 15:17:57 +07:00
Pierre Joye bb09a211d3 simplify, no need to allocate color here as it always true color 2016-06-19 15:16:58 +07:00
Pierre Joye 132cadd4c0 Merge branch 'GD-2.2'
* GD-2.2:
  use unsigned int for index
  fix memory leak
  add email and quotes (just to be sure)
  use 2.2 for now
  add key for travis-coverity
  Fix 228: gdAssertImageEquals() can't be used

Conflicts:
	.travis.yml
2016-06-19 03:02:05 +07:00
Pierre Joye 489e90f7aa use unsigned int for index 2016-06-19 02:40:31 +07:00
Pierre Joye 75fb8f02ef fix memory leak 2016-06-19 02:33:02 +07:00
Christoph M. Becker 80ce084567 Fix #170: XBM images require width to be multiple of 8
We remove this limitation by fixing the underlying implementation bug,
and add a respective regression test to the suite.
2016-06-16 17:46:06 +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
Pierre Joye 493283ee2d Merge branch 'GD-2.2'
* GD-2.2:
  fix #232, set output argument dst to NULL on errror
2016-06-15 17:58:08 +07:00
Pierre Joye 81d94b1c66 fix #232, set output argument dst to NULL on errror 2016-06-15 17:57:50 +07:00
Pierre Joye 34b705b0ce Merge branch 'GD-2.2'
* GD-2.2:
  fix 232, set output argument dst to NULL on errror
2016-06-15 17:18:05 +07:00
Pierre Joye 02c6925404 fix 232, set output argument dst to NULL on errror 2016-06-15 17:17:20 +07:00
Pierre Joye e5dd556cbd let try again to make gcc/clang on travis happy. ok, cherrypicking next time. 2016-06-15 13:31:30 +07:00
Pierre Joye bd44bce836 Merge branch 'GD-2.2'
* GD-2.2:
  let try again to make gcc/clang on travis happy...
2016-06-15 13:14:39 +07:00
Pierre Joye 8b32817401 let try again to make gcc/clang on travis happy... 2016-06-15 13:14:14 +07:00
Pierre Joye b21c42bfd6 Merge branch 'GD-2.2'
* GD-2.2:
  fix build --enable-werror
2016-06-15 12:42:44 +07:00
Pierre Joye 8ad45d4de0 fix build --enable-werror 2016-06-15 12:39:40 +07:00
Pierre Joye 50d8b568e4 Merge branch 'GD-2.2'
* GD-2.2:
  fix build (warning as error). Now why it does not happen with gcc... todo++
2016-06-15 12:04:01 +07:00
Pierre Joye 9df878a400 fix build (warning as error). Now why it does not happen with gcc... todo++ 2016-06-15 12:03:37 +07:00
Pierre Joye e22448e6dd Merge branch 'GD-2.2'
* GD-2.2:
  fix #227 drop usage of GD_BILINEAR_FIXED and GD_BICUBIC_FIXED for gdImageRotateInterpolated, the quality does not match expectation. It is also trickier to maintain for little gain. The generic method is used and will be optimized for 2.3 to match fixed pt performance, if necessary. Also use png for comparison to avoid jpeg artifact, making impossible to exactly  compare results
  fix #227 drop usage of GD_BILINEAR_FIXED and GD_BICUBIC_FIXED for gdImageRotateInterpolated, the quality does not match expectation. It is also trickier to maintain for little gain. The generic method is used and will be optimized for 2.3 to match fixed pt performance, if necessary. Also use png for comparison to avoid jpeg artifact, making impossible to exactly  compare results
  fix #227 drop usage of GD_BILINEAR_FIXED and GD_BICUBIC_FIXED for gdImageRotateInterpolated, the quality does not match expectation. It is also trickier to maintain for little gain. The generic method is used and will be optimized for 2.3 to match fixed pt performance, if necessary. Also use png for comparison to avoid jpeg artifact, making impossible to exactly  compare results
  WS
  #230 fix crash on fail
  gdTestAssert should not accept any message. Also crashes if assert failed

Conflicts:
	tests/gdimagerotate/bug00067.c
	tests/gdtest/gdtest.c
2016-06-15 09:53:28 +07:00
Pierre Joye 910984af15 fix #227 drop usage of GD_BILINEAR_FIXED and GD_BICUBIC_FIXED for gdImageRotateInterpolated, the quality does not match expectation. It is also trickier to maintain for little gain. The generic method is used and will be optimized for 2.3 to match fixed pt performance, if necessary. Also use png for comparison to avoid jpeg artifact, making impossible to exactly compare results 2016-06-15 09:47:24 +07:00
Pierre Joye bd6d2e101f fix #227 drop usage of GD_BILINEAR_FIXED and GD_BICUBIC_FIXED for gdImageRotateInterpolated, the quality does not match expectation. It is also trickier to maintain for little gain. The generic method is used and will be optimized for 2.3 to match fixed pt performance, if necessary. Also use png for comparison to avoid jpeg artifact, making impossible to exactly compare results 2016-06-15 09:38:22 +07:00
Pierre Joye c90ab16521 Merge branch 'GD-2.2'
* GD-2.2:
  nuke unused variable
2016-06-12 14:31:48 +07:00
Pierre Joye 71f2fcda3e nuke unused variable 2016-06-12 14:31:27 +07:00
Pierre Joye a0ab07761e Merge branch 'GD-2.2'
* GD-2.2:
  fix #224 and fix #225 and overal quality are significantly improved, code much simpler as well
2016-06-12 13:41:17 +07:00
Pierre Joye 6267414dc2 fix #224 and fix #225 and overal quality are significantly improved, code much simpler as well 2016-06-12 13:40:15 +07:00
Pierre Joye b883831f1f Merge branch 'GD-2.2'
* GD-2.2:
  fix #223 pass coordiates as double to interpolated pixel, simplify edges and bg color checks and correct the calc of the delta between virtual pixels and pixels used for the interpolation. Summary: better quality
  gitignore: add missing entries #172 #218
  clean up new gdTransformAffineBoundingBox tests #221
2016-06-11 08:33:10 +07:00
Pierre Joye 2b26be874d fix #223 pass coordiates as double to interpolated pixel, simplify edges and bg color checks and correct the calc of the delta between virtual pixels and pixels used for the interpolation. Summary: better quality 2016-06-11 08:31:39 +07:00
Mike Frysinger 046290cd9e travis: update comments and add git status check
Want to make sure we don't forget to update .gitignore files!
2016-06-10 14:45:48 -04:00
Pierre Joye ba25cd0384 Merge branch 'GD-2.2'
* GD-2.2:
  fix #221 gdTransformAffineBoundingBox rounding error
2016-06-10 19:39:28 +07:00
Pierre Joye b30fdbf319 fix #221 gdTransformAffineBoundingBox rounding error 2016-06-10 19:38:39 +07:00
Pierre Joye 45f16d0769 Merge branch 'GD-2.2'
* GD-2.2:
  fix #172 single line rectangle creates wriclers. Simplify test.

Conflicts:
	tests/gdimagerectangle/github_bug_00172.c
2016-06-09 10:56:18 +07:00
Pierre Joye 19788a221a fix #172 single line rectangle creates wriclers. Simplify test. 2016-06-09 10:50:30 +07:00
Pierre Joye 8438ce5dd6 Merge branch 'GD-2.2'
* GD-2.2:
  fix #215, invalid color index, missing case for invalid border
2016-06-08 11:23:57 +07:00
Pierre Joye 6f5c4084c1 fix #215, invalid color index, missing case for invalid border 2016-06-08 11:23:38 +07:00
Pierre Joye 5bfcc2c7be Merge branch 'GD-2.2'
* GD-2.2:
  fix #218 zero width or height parameter can lead to crash
  prevent double definitions
2016-06-08 10:40:46 +07:00
Pierre Joye 77309c419c fix #218 zero width or height parameter can lead to crash 2016-06-08 10:39:27 +07:00
Pierre Joye e8bfada239 Merge branch 'GD-2.2'
* GD-2.2:
  fix #215 gdImageFillToBorder stack-overflow when invalid color is used
  tests: add bug_github_18 to gitignore #18
  tests: fix typo in test name #18
2016-06-04 23:14:57 +07:00
Pierre Joye 77f619d482 fix #215 gdImageFillToBorder stack-overflow when invalid color is used 2016-06-04 23:09:01 +07:00
Mike Frysinger adb05a4e40 ifdef out some unused pixel helpers
These don't seem to ever have been used, but since they follow API
patterns seen by other funcs in here, let's just #if 0 them out for
now.  This fixes unused func -Werror failures.
2016-06-03 20:37:05 -04:00
Pierre Joye fa82e9532e merge 2016-06-04 00:26:44 +07:00
Pierre Joye 7fad13a913 Fix #18 Poor maximum jpeg quality 2016-06-04 00:20:08 +07:00
Christoph M. Becker 5a85d6c3e3 gdImageRectangle: support any relative points
Contrary to gdImageFilledRectangle(), gdImageRectangle() has the
documented limitation that the given points have to be the upper
left and the lower right corner, respectively.  However, libgd
already caters to upper right / lower left pairs, and not
catering to the other two combinations seems to be an oversight.

Fixes #177.
2016-05-20 11:03:37 -04:00
Mike Frysinger a49ebbf1ed release gd-2.2.1 2016-05-20 10:39:04 -04:00
Ondřej Surý 4d29684fd4 CVE-2015-8874 2016-05-20 10:37:44 -04:00
Ondřej Surý 38241013cc CVE-2015-8874 2016-05-20 10:52:23 +02:00
Mike Frysinger a881959c02 master is now 2.3.0-dev 2016-05-19 22:50:13 -04:00
Mike Frysinger fe199edee5 release gd-2.2.0 2016-05-19 22:49:06 -04:00
Mike Frysinger c9a4a85f38 libimagequant: fix integration
The symbol was being set up in cmake but not on the autotools side.
Clean this up to be like other external libraries.

We need to pull in some openmp logic as it's not uncommon for the lib
to be built with openmp support.  When we test for it, we need to do
so with openmp flags.

Fixes #137.
2016-05-18 03:03:50 -04:00
Mike Frysinger b64c996b07 build: fix GDLIB_REVISION collision
We are using GDLIB_REVISION to refer to the gd version string (the "z"
in "x.y.z"), and we are using it to control the libtool revision field.
This leads to problems where the version increases (e.g. "2.1.1") but
the libtool revision doesn't (e.g. "0").  So scripts end up seeing a
revision of "0" in their output instead of "1".

Namespace the libtool version variables with "_LT_" to avoid any more
collisions.

Fixes #140.
2016-05-18 02:34:45 -04:00
Mike Frysinger 1239832a09 configure/cmake: unify header checks and config.h generation
Rather than hand maintain config.h.cmake (which is already out of date),
re-use the autogenerated config.h from autoheader.
2016-05-17 23:06:14 -04:00
Mike Frysinger 2733b623ee tga: cleanup/simplify a bit
Try to standardize the internals a little bit and simplify the read
paths to abort early on when we know we won't actually handle the
input format.  Avoid resetting pointers that are on the stack or we
release as it's a waste of code.
2016-05-14 03:51:26 -04:00
Mike Frysinger 96d5687689 tga: fix two memory corruption bugs #159
First, if the tga input had an ID set, we'd read this into the pointer
itself (and the memory after it in the struct/heap) instead of the memory
allocated to hold it.  This bug has been around since the tga code was
first added.  We'd basically corrupt memory all the time since most tga
files out there have an ID set up (like a datestamp).

Second, make sure we reject invalid images that would cause overflows in
the allocation path.  We tried to check for this already, but we used the
wrong type (we checked uint8_t but allocated int).

Fixes #159.
2016-05-14 03:45:42 -04:00
Mike Frysinger e5306635ff png: fix some memory leaks w/invalid images
The use of setjmp in this function was slightly incorrect: we store
pointers to allocated memory in stack variables, but we didn't call
setjmp again afterwards.  Optimization might place those in registers
which would clobber their values on the next longjmp.  Make sure we
call setjmp after every allocation to update the state.

As part of the cleanup, unify all the error code paths so we don't
have to worry about every if statement being fully correct.
2016-05-14 02:44:31 -04:00
Mike Frysinger 82b80dcb70 gif: avoid out-of-bound reads of masks array #209
When given invalid inputs, we might be fed the EOF marker before it is
actually the EOF.  The gif logic assumes once it sees the EOF marker,
there won't be any more data, so it leaves the cur_bits index possibly
negative.  So when we get more data, we underflow the masks array.

Flag it so we don't try to output anything more.  The image is invalid,
so we shouldn't be truncating any valid inputs.

This fixes #209.
2016-05-14 02:13:15 -04:00
Mike Frysinger 4dc1a2d793 xbm: avoid stack overflow (read) with large names #211
We use the name passed in to printf into a local stack buffer which is
limited to 4000 bytes.  So given a large enough value, lots of stack
data is leaked.  Rewrite the code to do simple memory copies with most
of the strings to avoid that issue, and only use stack buffer for small
numbers of constant size.

This closes #211.
2016-05-14 01:38:18 -04:00
Mike Frysinger b083ec17ad cmake: update build files to match autotools more
Clean up redundant header logic and focus on what we actually care about:
whether specific headers exist.

Update the program list to omit programs when required libs are not found.
2016-05-14 01:01:44 -04:00
Mike Frysinger 2db153a93e webpng: rewrite & cleanup to use getopt
The adhoc arg parsing is a pain to maintain.  Rewrite it all to use
getopt to make it much more simple and robust.
2016-05-14 00:17:12 -04:00
Mike Frysinger 75c38f6b32 fix various gcc/clang warnings found with -Wall 2016-05-13 22:19:26 -04:00
David Drysdale 4e61c9b021 tiff: fix leak in gdImageCreateFromTiffCtx()
The ephemeral tiff_handle used when interacting with libtiff needs
to be freed.
2016-05-01 01:44:02 -04:00
Mike Frysinger 658f168874 gd2: fix double free when processing invalid headers
This closes #208.
2016-04-30 21:55:17 -04:00
xicilion 09d2d01315 webp: fix double free
The filedata & temp pointers are assigned the same return value, so
trying to free both of them at the end makes no sense and results in
a double free error.  Drop one of them.
2016-04-30 21:31:02 -04:00
Mike Frysinger cd1d964179 libgd: update & sort cmake installed headers #164
The cmake side of things was missing two installed headers.
2016-04-30 21:12:51 -04:00
Mike Frysinger e16310b27c libgd: update & sort source lists
The Makefile.am has no changes other than sorting & unwrapping the files
to make it a bit more readable (and dropping duplicate entries).

The CMakeLists.txt gains a few files that were added recently but left
out of the cmake build.

Closes #183.
2016-04-30 21:00:31 -04:00
Remi Collet 982d4888a5 revert... unneeded 2016-04-27 08:23:09 +02:00
Remi Collet a5b5c2722d Fix memory leak
From:
http://git.php.net/?p=php-src.git;a=commitdiff;h=61c7a06e7c19d9b408db1129efa0959a0acbf0b1
2016-04-27 08:10:52 +02:00
Mike Frysinger 2bb97f407c gd2: handle corrupt images better (CVE-2016-3074)
Make sure we do some range checking on corrupted chunks.

Thanks to Hans Jerry Illikainen <hji@dyntopia.com> for indepth report
and reproducer information.  Made for easy test case writing :).
2016-04-16 03:51:22 -04:00
Matt Bosworth 4e53ed7992 Added support for reading and writing TIFFTAG_XRESOLUTION and
TIFFTAG_YRESOLUTION.  Includes a unit test.
2016-01-22 12:52:50 -08:00
Mike Frysinger 6913dd3cd2 bmp: use double variant of ceil func
We use ceill and ceil in this code, but it's not clear we need the long
double variant of ceill here.  The input multiply is already done with
double precision (the 0.1 literal is a double), and not all C libraries
offer long double variants.  Change to ceil and see if anyone notices.

Closes issue #123.
2016-01-11 00:02:05 -05:00
sherif-elmetainy e87ec88e1c :fix and unit test for crash issue in gdImageFillTiled 2016-01-09 23:02:12 +02:00
Mike Frysinger 73ab7c7d28 Merge pull request #182 from leoyanggit/fix_build_static
Make BUILD_SHARED_LIBS configurable
2015-12-23 11:59:17 -05:00
Mike Frysinger e08acb0565 Merge pull request #153 from davidchappelle/master
A few minor patches for libgd
2015-12-23 11:58:31 -05:00
Jitendar Kumar 78dad445b3 circletexttest: check image creation return value
In circletexttest.c, return value of gdImageCreateFromJpeg() and
gdImageCreateTrueColor() must be checked before dereferencing.
2015-12-23 11:54:33 -05:00
Peter Jas 8f69034043 code: Adds missing methods for absent libz case. 2015-11-24 05:27:37 +00:00
Peter Jas 2e04a67853 win: Use an external snprintf hook.
* For VS2013 and below, it will compile and additional file `src/snprintf.c`, which contains the fallback implementation. The
function is included with `extern` in other files where required.
* In `src/CMakeLists.txt`, `snprintf.c` is included in sources conditionally; only for
VS2013 and below.
* Note that I have also guarded it with condition inside the `snprintf.c` file, so if any consumer/downstream is not using `cmake` but their own build system (say gyp), this will still prevent them redefining snprintf for VS2015 even if they add `/src/snprintf.c` in to-be-compiled sources unconditionally.
2015-11-23 21:18:37 +00:00
Jitendar Kumar dd4828665c Logical Operation && has no Impact on expression result .
Line 1746:  second operand of  '&&' operator has no impact on expression result. 
It looks a typo mistake.
2015-11-09 07:28:25 +05:30
David Chappelle 9ea30979a4 Prevent duplicate macro definition errors/warnings
It is the responsibility of the build infrastructure or user to set or
not set NDEBUG. For the time being this is a workaround in the case
where NDEBUG is set by the build infrastructure or user which prevents
the compiler from generating macro redefiniton warnings/errors. A longer
term fix will require changes to booststrap (aka configure) as well as
cmake (aka CMakeLists.txt).
2015-08-27 14:29:19 -04:00
David Chappelle 40f42c0f75 Fix compiler warnings when checking interpolation_id
The interpolation_id is an enum that contains only positive
values. As a result, checking if it less than 0 generates a
compiler warning since the conditional check is always false.
2015-08-27 14:25:51 -04:00
Leo Yang 7147b646f4 Make BUILD_SHARED_LIBS configurable
As previously build both shared and static if BUILD_SHARED_LIBS is ON.
Otherwise build static only.
2015-08-27 13:11:37 -04:00
Vladimir Mitrovic 4751b606fa gdImageScaleTwoPass memory leak fix
Fixing memory leak in gdImageScaleTwoPass, as reported by @cmb69 and
confirmed by @vapier.  This bug actually bit me in production and I'm
very thankful that it was reported with an easy fix.

Fixes #173.
2015-08-05 03:01:06 +02:00