Unify error handling of bundled and external libgd

There's no need anymore to call an own error handler directly. Instead we
register our error handler and call libgd's error functions (which will
forward). We do this regardless of compiling with the bundled or an external
libgd.
This commit is contained in:
Christoph M. Becker 2016-10-07 01:06:24 +02:00
parent 8754b191f7
commit 432e16cb58
13 changed files with 236 additions and 141 deletions

View File

@ -63,9 +63,7 @@
static int le_gd, le_gd_font;
#include <gd.h>
#ifndef HAVE_GD_BUNDLED
# include <gd_errors.h>
#endif
#include <gd_errors.h>
#include <gdfontt.h> /* 1 Tiny font */
#include <gdfonts.h> /* 2 Small font */
#include <gdfontmb.h> /* 3 Medium bold font */
@ -1028,7 +1026,6 @@ static void php_free_gd_font(zend_resource *rsrc)
}
/* }}} */
#ifndef HAVE_GD_BUNDLED
/* {{{ php_gd_error_method
*/
void php_gd_error_method(int type, const char *format, va_list args)
@ -1049,7 +1046,6 @@ void php_gd_error_method(int type, const char *format, va_list args)
php_verror(NULL, "", type, format, args TSRMLS_CC);
}
/* }}} */
#endif
/* {{{ PHP_MINIT_FUNCTION
*/
@ -1061,9 +1057,8 @@ PHP_MINIT_FUNCTION(gd)
#if HAVE_GD_BUNDLED && HAVE_LIBFREETYPE
gdFontCacheMutexSetup();
#endif
#ifndef HAVE_GD_BUNDLED
gdSetErrorMethod(php_gd_error_method);
#endif
REGISTER_INI_ENTRIES();
REGISTER_LONG_CONSTANT("IMG_GIF", 1, CONST_CS | CONST_PERSISTENT);

View File

@ -4,6 +4,7 @@
#include <stdlib.h>
#include "gd.h"
#include "gdhelpers.h"
#include "gd_errors.h"
#include "php.h"
@ -91,31 +92,80 @@ static const unsigned char gd_toascii[256] =
extern int gdCosT[];
extern int gdSinT[];
/**
* Group: Error Handling
*/
void gd_stderr_error(int priority, const char *format, va_list args)
{
switch (priority) {
case GD_ERROR:
fputs("GD Error: ", stderr);
break;
case GD_WARNING:
fputs("GD Warning: ", stderr);
break;
case GD_NOTICE:
fputs("GD Notice: ", stderr);
break;
case GD_INFO:
fputs("GD Info: ", stderr);
break;
case GD_DEBUG:
fputs("GD Debug: ", stderr);
break;
}
vfprintf(stderr, format, args);
fflush(stderr);
}
static gdErrorMethod gd_error_method = gd_stderr_error;
static void _gd_error_ex(int priority, const char *format, va_list args)
{
if (gd_error_method) {
gd_error_method(priority, format, args);
}
}
void gd_error(const char *format, ...)
{
va_list args;
va_start(args, format);
_gd_error_ex(GD_WARNING, format, args);
va_end(args);
}
void gd_error_ex(int priority, const char *format, ...)
{
va_list args;
va_start(args, format);
_gd_error_ex(priority, format, args);
va_end(args);
}
/*
Function: gdSetErrorMethod
*/
void gdSetErrorMethod(gdErrorMethod error_method)
{
gd_error_method = error_method;
}
/*
Function: gdClearErrorMethod
*/
void gdClearErrorMethod(void)
{
gd_error_method = gd_stderr_error;
}
static void gdImageBrushApply(gdImagePtr im, int x, int y);
static void gdImageTileApply(gdImagePtr im, int x, int y);
static int gdAlphaOverlayColor(int src, int dst, int max);
int gdImageGetTrueColorPixel(gdImagePtr im, int x, int y);
void php_gd_error_ex(int type, const char *format, ...)
{
va_list args;
va_start(args, format);
php_verror(NULL, "", type, format, args);
va_end(args);
}
void php_gd_error(const char *format, ...)
{
va_list args;
va_start(args, format);
php_verror(NULL, "", E_WARNING, format, args);
va_end(args);
}
gdImagePtr gdImageCreate (int sx, int sy)
{
int i;

View File

@ -46,10 +46,6 @@ extern "C" {
#include <stdio.h>
#include "gd_io.h"
void php_gd_error_ex(int type, const char *format, ...);
void php_gd_error(const char *format, ...);
/* The maximum number of palette entries in palette-based images.
In the wonderful new world of gd 2.0, you can of course have
@ -289,6 +285,10 @@ typedef struct {
/* Text functions take these. */
typedef gdFont *gdFontPtr;
typedef void(*gdErrorMethod)(int, const char *, va_list);
void gdSetErrorMethod(gdErrorMethod);
void gdClearErrorMethod(void);
/**
* Group: Types

46
ext/gd/libgd/gd_errors.h Normal file
View File

@ -0,0 +1,46 @@
#ifndef GD_ERRORS_H
#define GD_ERRORS_H
#ifndef _WIN32
# include <syslog.h>
#else
/*
* priorities/facilities are encoded into a single 32-bit quantity, where the
* bottom 3 bits are the priority (0-7) and the top 28 bits are the facility
* (0-big number). Both the priorities and the facilities map roughly
* one-to-one to strings in the syslogd(8) source code. This mapping is
* included in this file.
*
* priorities (these are ordered)
*/
# define LOG_EMERG 0 /* system is unusable */
# define LOG_ALERT 1 /* action must be taken immediately */
# define LOG_CRIT 2 /* critical conditions */
# define LOG_ERR 3 /* error conditions */
# define LOG_WARNING 4 /* warning conditions */
# define LOG_NOTICE 5 /* normal but significant condition */
# define LOG_INFO 6 /* informational */
# define LOG_DEBUG 7 /* debug-level messages */
#endif
/*
LOG_EMERG system is unusable
LOG_ALERT action must be taken immediately
LOG_CRIT critical conditions
LOG_ERR error conditions
LOG_WARNING warning conditions
LOG_NOTICE normal, but significant, condition
LOG_INFO informational message
LOG_DEBUG debug-level message
*/
#define GD_ERROR LOG_ERR
#define GD_WARNING LOG_WARNING
#define GD_NOTICE LOG_NOTICE
#define GD_INFO LOG_INFO
#define GD_DEBUG LOG_DEBUG
void gd_error(const char *format, ...);
void gd_error_ex(int priority, const char *format, ...);
#endif

View File

@ -16,6 +16,7 @@
#include <string.h>
#include <stdlib.h>
#include "gd.h"
#include "gd_errors.h"
#include "gdhelpers.h"
#include <zlib.h>
@ -60,7 +61,7 @@ static int _gd2GetHeader(gdIOCtxPtr in, int *sx, int *sy, int *cs, int *vers, in
int sidx;
int nc;
GD2_DBG(php_gd_error("Reading gd2 header info"));
GD2_DBG(gd_error("Reading gd2 header info"));
for (i = 0; i < 4; i++) {
ch = gdGetC(in);
@ -71,11 +72,11 @@ static int _gd2GetHeader(gdIOCtxPtr in, int *sx, int *sy, int *cs, int *vers, in
}
id[4] = 0;
GD2_DBG(php_gd_error("Got file code: %s", id));
GD2_DBG(gd_error("Got file code: %s", id));
/* Equiv. of 'magick'. */
if (strcmp(id, GD2_ID) != 0) {
GD2_DBG(php_gd_error("Not a valid gd2 file"));
GD2_DBG(gd_error("Not a valid gd2 file"));
goto fail1;
}
@ -83,32 +84,32 @@ static int _gd2GetHeader(gdIOCtxPtr in, int *sx, int *sy, int *cs, int *vers, in
if (gdGetWord(vers, in) != 1) {
goto fail1;
}
GD2_DBG(php_gd_error("Version: %d", *vers));
GD2_DBG(gd_error("Version: %d", *vers));
if ((*vers != 1) && (*vers != 2)) {
GD2_DBG(php_gd_error("Bad version: %d", *vers));
GD2_DBG(gd_error("Bad version: %d", *vers));
goto fail1;
}
/* Image Size */
if (!gdGetWord(sx, in)) {
GD2_DBG(php_gd_error("Could not get x-size"));
GD2_DBG(gd_error("Could not get x-size"));
goto fail1;
}
if (!gdGetWord(sy, in)) {
GD2_DBG(php_gd_error("Could not get y-size"));
GD2_DBG(gd_error("Could not get y-size"));
goto fail1;
}
GD2_DBG(php_gd_error("Image is %dx%d", *sx, *sy));
GD2_DBG(gd_error("Image is %dx%d", *sx, *sy));
/* Chunk Size (pixels, not bytes!) */
if (gdGetWord(cs, in) != 1) {
goto fail1;
}
GD2_DBG(php_gd_error("ChunkSize: %d", *cs));
GD2_DBG(gd_error("ChunkSize: %d", *cs));
if ((*cs < GD2_CHUNKSIZE_MIN) || (*cs > GD2_CHUNKSIZE_MAX)) {
GD2_DBG(php_gd_error("Bad chunk size: %d", *cs));
GD2_DBG(gd_error("Bad chunk size: %d", *cs));
goto fail1;
}
@ -116,10 +117,10 @@ static int _gd2GetHeader(gdIOCtxPtr in, int *sx, int *sy, int *cs, int *vers, in
if (gdGetWord(fmt, in) != 1) {
goto fail1;
}
GD2_DBG(php_gd_error("Format: %d", *fmt));
GD2_DBG(gd_error("Format: %d", *fmt));
if ((*fmt != GD2_FMT_RAW) && (*fmt != GD2_FMT_COMPRESSED) && (*fmt != GD2_FMT_TRUECOLOR_RAW) && (*fmt != GD2_FMT_TRUECOLOR_COMPRESSED)) {
GD2_DBG(php_gd_error("Bad data format: %d", *fmt));
GD2_DBG(gd_error("Bad data format: %d", *fmt));
goto fail1;
}
@ -127,17 +128,17 @@ static int _gd2GetHeader(gdIOCtxPtr in, int *sx, int *sy, int *cs, int *vers, in
if (gdGetWord(ncx, in) != 1) {
goto fail1;
}
GD2_DBG(php_gd_error("%d Chunks Wide", *ncx));
GD2_DBG(gd_error("%d Chunks Wide", *ncx));
/* # of chunks high */
if (gdGetWord(ncy, in) != 1) {
goto fail1;
}
GD2_DBG(php_gd_error("%d Chunks vertically", *ncy));
GD2_DBG(gd_error("%d Chunks vertically", *ncy));
if (gd2_compressed(*fmt)) {
nc = (*ncx) * (*ncy);
GD2_DBG(php_gd_error("Reading %d chunk index entries", nc));
GD2_DBG(gd_error("Reading %d chunk index entries", nc));
if (overflow2(sizeof(t_chunk_info), nc)) {
goto fail1;
}
@ -167,7 +168,7 @@ static int _gd2GetHeader(gdIOCtxPtr in, int *sx, int *sy, int *cs, int *vers, in
*chunkIdx = cidx;
}
GD2_DBG(php_gd_error("gd2 header complete"));
GD2_DBG(gd_error("gd2 header complete"));
return 1;
@ -180,7 +181,7 @@ static gdImagePtr _gd2CreateFromFile (gdIOCtxPtr in, int *sx, int *sy, int *cs,
gdImagePtr im;
if (_gd2GetHeader (in, sx, sy, cs, vers, fmt, ncx, ncy, cidx) != 1) {
GD2_DBG(php_gd_error("Bad GD2 header"));
GD2_DBG(gd_error("Bad GD2 header"));
goto fail1;
}
@ -190,15 +191,15 @@ static gdImagePtr _gd2CreateFromFile (gdIOCtxPtr in, int *sx, int *sy, int *cs,
im = gdImageCreate(*sx, *sy);
}
if (im == NULL) {
GD2_DBG(php_gd_error("Could not create gdImage"));
GD2_DBG(gd_error("Could not create gdImage"));
goto fail2;
}
if (!_gdGetColors(in, im, (*vers) == 2)) {
GD2_DBG(php_gd_error("Could not read color palette"));
GD2_DBG(gd_error("Could not read color palette"));
goto fail3;
}
GD2_DBG(php_gd_error("Image palette completed: %d colours", im->colorsTotal));
GD2_DBG(gd_error("Image palette completed: %d colours", im->colorsTotal));
return im;
@ -215,24 +216,24 @@ static int _gd2ReadChunk (int offset, char *compBuf, int compSize, char *chunkBu
int zerr;
if (gdTell(in) != offset) {
GD2_DBG(php_gd_error("Positioning in file to %d", offset));
GD2_DBG(gd_error("Positioning in file to %d", offset));
gdSeek(in, offset);
} else {
GD2_DBG(php_gd_error("Already Positioned in file to %d", offset));
GD2_DBG(gd_error("Already Positioned in file to %d", offset));
}
/* Read and uncompress an entire chunk. */
GD2_DBG(php_gd_error("Reading file"));
GD2_DBG(gd_error("Reading file"));
if (gdGetBuf(compBuf, compSize, in) != compSize) {
return FALSE;
}
GD2_DBG(php_gd_error("Got %d bytes. Uncompressing into buffer of %d bytes", compSize, (int)*chunkLen));
GD2_DBG(gd_error("Got %d bytes. Uncompressing into buffer of %d bytes", compSize, (int)*chunkLen));
zerr = uncompress((unsigned char *) chunkBuf, chunkLen, (unsigned char *) compBuf, compSize);
if (zerr != Z_OK) {
GD2_DBG(php_gd_error("Error %d from uncompress", zerr));
GD2_DBG(gd_error("Error %d from uncompress", zerr));
return FALSE;
}
GD2_DBG(php_gd_error("Got chunk"));
GD2_DBG(gd_error("Got chunk"));
return TRUE;
}
@ -304,7 +305,7 @@ gdImagePtr gdImageCreateFromGd2Ctx (gdIOCtxPtr in)
chunkBuf = gdCalloc(chunkMax, 1);
compBuf = gdCalloc(compMax, 1);
GD2_DBG(php_gd_error("Largest compressed chunk is %d bytes", compMax));
GD2_DBG(gd_error("Largest compressed chunk is %d bytes", compMax));
}
/* Read the data... */
@ -316,13 +317,13 @@ gdImagePtr gdImageCreateFromGd2Ctx (gdIOCtxPtr in)
yhi = im->sy;
}
GD2_DBG(php_gd_error("Processing Chunk %d (%d, %d), y from %d to %d", chunkNum, cx, cy, ylo, yhi));
GD2_DBG(gd_error("Processing Chunk %d (%d, %d), y from %d to %d", chunkNum, cx, cy, ylo, yhi));
if (gd2_compressed(fmt)) {
chunkLen = chunkMax;
if (!_gd2ReadChunk(chunkIdx[chunkNum].offset, compBuf, chunkIdx[chunkNum].size, (char *) chunkBuf, &chunkLen, in)) {
GD2_DBG(php_gd_error("Error reading comproessed chunk"));
GD2_DBG(gd_error("Error reading comproessed chunk"));
goto fail2;
}
@ -369,7 +370,7 @@ gdImagePtr gdImageCreateFromGd2Ctx (gdIOCtxPtr in)
}
}
GD2_DBG(php_gd_error("Freeing memory"));
GD2_DBG(gd_error("Freeing memory"));
if (chunkBuf) {
gdFree(chunkBuf);
@ -381,7 +382,7 @@ gdImagePtr gdImageCreateFromGd2Ctx (gdIOCtxPtr in)
gdFree(chunkIdx);
}
GD2_DBG(php_gd_error("Done"));
GD2_DBG(gd_error("Done"));
return im;
@ -455,7 +456,7 @@ gdImagePtr gdImageCreateFromGd2PartCtx (gdIOCtx * in, int srcx, int srcy, int w,
goto fail1;
}
GD2_DBG(php_gd_error("File size is %dx%d", fsx, fsy));
GD2_DBG(gd_error("File size is %dx%d", fsx, fsy));
/* This is the difference - make a file based on size of chunks. */
if (gd2_truecolor(fmt)) {
@ -470,7 +471,7 @@ gdImagePtr gdImageCreateFromGd2PartCtx (gdIOCtx * in, int srcx, int srcy, int w,
if (!_gdGetColors(in, im, vers == 2)) {
goto fail2;
}
GD2_DBG(php_gd_error("Image palette completed: %d colours", im->colorsTotal));
GD2_DBG(gd_error("Image palette completed: %d colours", im->colorsTotal));
/* Process the header info */
nc = ncx * ncy;
@ -519,7 +520,7 @@ gdImagePtr gdImageCreateFromGd2PartCtx (gdIOCtx * in, int srcx, int srcy, int w,
/* Remember file position of image data. */
dstart = gdTell(in);
GD2_DBG(php_gd_error("Data starts at %d", dstart));
GD2_DBG(gd_error("Data starts at %d", dstart));
/* Loop through the chunks. */
for (cy = scy; (cy <= ecy); cy++) {
@ -537,10 +538,10 @@ gdImagePtr gdImageCreateFromGd2PartCtx (gdIOCtx * in, int srcx, int srcy, int w,
xhi = fsx;
}
GD2_DBG(php_gd_error("Processing Chunk (%d, %d), from %d to %d", cx, cy, ylo, yhi));
GD2_DBG(gd_error("Processing Chunk (%d, %d), from %d to %d", cx, cy, ylo, yhi));
if (!gd2_compressed(fmt)) {
GD2_DBG(php_gd_error("Using raw format data"));
GD2_DBG(gd_error("Using raw format data"));
if (im->trueColor) {
dpos = (cy * (cs * fsx) * 4 + cx * cs * (yhi - ylo) * 4) + dstart;
} else {
@ -549,23 +550,23 @@ gdImagePtr gdImageCreateFromGd2PartCtx (gdIOCtx * in, int srcx, int srcy, int w,
/* gd 2.0.11: gdSeek returns TRUE on success, not 0. Longstanding bug. 01/16/03 */
if (!gdSeek(in, dpos)) {
php_gd_error_ex(E_WARNING, "Error from seek: %d", errno);
gd_error_ex(E_WARNING, "Error from seek: %d", errno);
goto fail2;
}
GD2_DBG(php_gd_error("Reading (%d, %d) from position %d", cx, cy, dpos - dstart));
GD2_DBG(gd_error("Reading (%d, %d) from position %d", cx, cy, dpos - dstart));
} else {
chunkNum = cx + cy * ncx;
chunkLen = chunkMax;
if (!_gd2ReadChunk (chunkIdx[chunkNum].offset, compBuf, chunkIdx[chunkNum].size, (char *)chunkBuf, &chunkLen, in)) {
php_gd_error("Error reading comproessed chunk");
gd_error("Error reading comproessed chunk");
goto fail2;
}
chunkPos = 0;
GD2_DBG(php_gd_error("Reading (%d, %d) from chunk %d", cx, cy, chunkNum));
GD2_DBG(gd_error("Reading (%d, %d) from chunk %d", cx, cy, chunkNum));
}
GD2_DBG(php_gd_error(" into (%d, %d) - (%d, %d)", xlo, ylo, xhi, yhi));
GD2_DBG(gd_error(" into (%d, %d) - (%d, %d)", xlo, ylo, xhi, yhi));
for (y = ylo; (y < yhi); y++) {
for (x = xlo; x < xhi; x++) {
@ -718,7 +719,7 @@ static void _gdImageGd2 (gdImagePtr im, gdIOCtx * out, int cs, int fmt)
*/
idxPos = gdTell(out);
idxSize = ncx * ncy * sizeof(t_chunk_info);
GD2_DBG(php_gd_error("Index size is %d", idxSize));
GD2_DBG(gd_error("Index size is %d", idxSize));
gdSeek(out, idxPos + idxSize);
chunkIdx = safe_emalloc(idxSize, sizeof(t_chunk_info), 0);
@ -727,8 +728,8 @@ static void _gdImageGd2 (gdImagePtr im, gdIOCtx * out, int cs, int fmt)
_gdPutColors (im, out);
GD2_DBG(php_gd_error("Size: %dx%d", im->sx, im->sy));
GD2_DBG(php_gd_error("Chunks: %dx%d", ncx, ncy));
GD2_DBG(gd_error("Size: %dx%d", im->sx, im->sy));
GD2_DBG(gd_error("Chunks: %dx%d", ncx, ncy));
for (cy = 0; (cy < ncy); cy++) {
for (cx = 0; (cx < ncx); cx++) {
@ -738,10 +739,10 @@ static void _gdImageGd2 (gdImagePtr im, gdIOCtx * out, int cs, int fmt)
yhi = im->sy;
}
GD2_DBG(php_gd_error("Processing Chunk (%dx%d), y from %d to %d", cx, cy, ylo, yhi));
GD2_DBG(gd_error("Processing Chunk (%dx%d), y from %d to %d", cx, cy, ylo, yhi));
chunkLen = 0;
for (y = ylo; (y < yhi); y++) {
GD2_DBG(php_gd_error("y=%d: ",y));
GD2_DBG(gd_error("y=%d: ",y));
xlo = cx * cs;
xhi = xlo + cs;
if (xhi > im->sx) {
@ -750,7 +751,7 @@ static void _gdImageGd2 (gdImagePtr im, gdIOCtx * out, int cs, int fmt)
if (gd2_compressed(fmt)) {
for (x = xlo; x < xhi; x++) {
GD2_DBG(php_gd_error("%d...",x));
GD2_DBG(gd_error("%d...",x));
if (im->trueColor) {
int p = im->tpixels[y][x];
chunkData[chunkLen++] = gdTrueColorGetAlpha(p);
@ -763,7 +764,7 @@ static void _gdImageGd2 (gdImagePtr im, gdIOCtx * out, int cs, int fmt)
}
} else {
for (x = xlo; x < xhi; x++) {
GD2_DBG(php_gd_error("%d, ",x));
GD2_DBG(gd_error("%d, ",x));
if (im->trueColor) {
gdPutInt(im->tpixels[y][x], out);
@ -772,21 +773,21 @@ static void _gdImageGd2 (gdImagePtr im, gdIOCtx * out, int cs, int fmt)
}
}
}
GD2_DBG(php_gd_error("y=%d done.",y));
GD2_DBG(gd_error("y=%d done.",y));
}
if (gd2_compressed(fmt)) {
compLen = compMax;
if (compress((unsigned char *) &compData[0], &compLen, (unsigned char *) &chunkData[0], chunkLen) != Z_OK) {
php_gd_error("Error from compressing");
gd_error("Error from compressing");
} else {
chunkIdx[chunkNum].offset = gdTell(out);
chunkIdx[chunkNum++].size = compLen;
GD2_DBG(php_gd_error("Chunk %d size %d offset %d", chunkNum, chunkIdx[chunkNum - 1].size, chunkIdx[chunkNum - 1].offset));
GD2_DBG(gd_error("Chunk %d size %d offset %d", chunkNum, chunkIdx[chunkNum - 1].size, chunkIdx[chunkNum - 1].offset));
if (gdPutBuf (compData, compLen, out) <= 0) {
/* Any alternate suggestions for handling this? */
php_gd_error_ex(E_WARNING, "Error %d on write", errno);
gd_error_ex(E_WARNING, "Error %d on write", errno);
}
}
}
@ -795,19 +796,19 @@ static void _gdImageGd2 (gdImagePtr im, gdIOCtx * out, int cs, int fmt)
if (gd2_compressed(fmt)) {
/* Save the position, write the index, restore position (paranoia). */
GD2_DBG(php_gd_error("Seeking %d to write index", idxPos));
GD2_DBG(gd_error("Seeking %d to write index", idxPos));
posSave = gdTell(out);
gdSeek(out, idxPos);
GD2_DBG(php_gd_error("Writing index"));
GD2_DBG(gd_error("Writing index"));
for (x = 0; x < chunkNum; x++) {
GD2_DBG(php_gd_error("Chunk %d size %d offset %d", x, chunkIdx[x].size, chunkIdx[x].offset));
GD2_DBG(gd_error("Chunk %d size %d offset %d", x, chunkIdx[x].size, chunkIdx[x].offset));
gdPutInt(chunkIdx[x].offset, out);
gdPutInt(chunkIdx[x].size, out);
}
gdSeek(out, posSave);
}
fail:
GD2_DBG(php_gd_error("Freeing memory"));
GD2_DBG(gd_error("Freeing memory"));
if (chunkData) {
gdFree(chunkData);
}
@ -817,7 +818,7 @@ fail:
if (chunkIdx) {
gdFree(chunkIdx);
}
GD2_DBG(php_gd_error("Done"));
GD2_DBG(gd_error("Done"));
}
void gdImageGd2 (gdImagePtr im, FILE * outFile, int cs, int fmt)

View File

@ -3,6 +3,7 @@
#include <string.h>
#include <stdlib.h>
#include "gd.h"
#include "gd_errors.h"
#include "php.h"
@ -361,7 +362,7 @@ GetDataBlock(gdIOCtx *fd, unsigned char *buf, int *ZeroDataBlockP)
} else {
tmp = estrdup("");
}
php_gd_error_ex(E_NOTICE, "[GetDataBlock returning %d: %s]", rv, tmp);
gd_error_ex(GD_NOTICE, "[GetDataBlock returning %d: %s]", rv, tmp);
efree(tmp);
}
return(rv);

View File

@ -52,20 +52,20 @@ void gdPutC (const unsigned char c, gdIOCtx * ctx)
void gdPutWord (int w, gdIOCtx * ctx)
{
IO_DBG (php_gd_error("Putting word..."));
IO_DBG (gd_error("Putting word..."));
(ctx->putC) (ctx, (unsigned char) (w >> 8));
(ctx->putC) (ctx, (unsigned char) (w & 0xFF));
IO_DBG (php_gd_error("put."));
IO_DBG (gd_error("put."));
}
void gdPutInt (int w, gdIOCtx * ctx)
{
IO_DBG (php_gd_error("Putting int..."));
IO_DBG (gd_error("Putting int..."));
(ctx->putC) (ctx, (unsigned char) (w >> 24));
(ctx->putC) (ctx, (unsigned char) ((w >> 16) & 0xFF));
(ctx->putC) (ctx, (unsigned char) ((w >> 8) & 0xFF));
(ctx->putC) (ctx, (unsigned char) (w & 0xFF));
IO_DBG (php_gd_error("put."));
IO_DBG (gd_error("put."));
}
int gdGetC (gdIOCtx * ctx)
@ -121,9 +121,9 @@ int gdGetInt (int *result, gdIOCtx * ctx)
int gdPutBuf (const void *buf, int size, gdIOCtx * ctx)
{
IO_DBG (php_gd_error("Putting buf..."));
IO_DBG (gd_error("Putting buf..."));
return (ctx->putBuf) (ctx, buf, size);
IO_DBG (php_gd_error("put."));
IO_DBG (gd_error("put."));
}
int gdGetBuf (void *buf, int size, gdIOCtx * ctx)
@ -133,14 +133,14 @@ int gdGetBuf (void *buf, int size, gdIOCtx * ctx)
int gdSeek (gdIOCtx * ctx, const int pos)
{
IO_DBG (php_gd_error("Seeking..."));
IO_DBG (gd_error("Seeking..."));
return ((ctx->seek) (ctx, pos));
IO_DBG (php_gd_error("Done."));
IO_DBG (gd_error("Done."));
}
long gdTell (gdIOCtx * ctx)
{
IO_DBG (php_gd_error("Telling..."));
IO_DBG (gd_error("Telling..."));
return ((ctx->tell) (ctx));
IO_DBG (php_gd_error ("told."));
IO_DBG (gd_error ("told."));
}

View File

@ -28,6 +28,7 @@
#include <string.h>
#include "gd.h"
#include "gd_errors.h"
/* TBB: move this up so include files are not brought in */
/* JCE: arrange HAVE_LIBJPEG so that it can be set in gd.h */
#ifdef HAVE_LIBJPEG
@ -66,14 +67,14 @@ static long php_jpeg_emit_message(j_common_ptr jpeg_info, int level)
* unless strace_level >= 3
*/
if ((jpeg_info->err->num_warnings == 0) || (jpeg_info->err->trace_level >= 3)) {
php_gd_error_ex(ignore_warning ? E_NOTICE : E_WARNING, "gd-jpeg, libjpeg: recoverable error: %s\n", message);
gd_error_ex(ignore_warning ? GD_NOTICE : GD_WARNING, "gd-jpeg, libjpeg: recoverable error: %s\n", message);
}
jpeg_info->err->num_warnings++;
} else {
/* strace msg, Show it if trace_level >= level. */
if (jpeg_info->err->trace_level >= level) {
php_gd_error_ex(E_NOTICE, "gd-jpeg, libjpeg: strace message: %s\n", message);
gd_error_ex(GD_NOTICE, "gd-jpeg, libjpeg: strace message: %s\n", message);
}
}
return 1;
@ -86,7 +87,7 @@ static void fatal_jpeg_error (j_common_ptr cinfo)
{
jmpbuf_wrapper *jmpbufw;
php_gd_error("gd-jpeg: JPEG library reports unrecoverable error: ");
gd_error("gd-jpeg: JPEG library reports unrecoverable error: ");
(*cinfo->err->output_message) (cinfo);
jmpbufw = (jmpbuf_wrapper *) cinfo->client_data;
@ -94,9 +95,9 @@ static void fatal_jpeg_error (j_common_ptr cinfo)
if (jmpbufw != 0) {
longjmp (jmpbufw->jmpbuf, 1);
php_gd_error_ex(E_ERROR, "gd-jpeg: EXTREMELY fatal error: longjmp returned control; terminating");
gd_error_ex(GD_ERROR, "gd-jpeg: EXTREMELY fatal error: longjmp returned control; terminating");
} else {
php_gd_error_ex(E_ERROR, "gd-jpeg: EXTREMELY fatal error: jmpbuf unrecoverable; terminating");
gd_error_ex(GD_ERROR, "gd-jpeg: EXTREMELY fatal error: jmpbuf unrecoverable; terminating");
}
exit (99);
@ -226,7 +227,7 @@ void gdImageJpegCtx (gdImagePtr im, gdIOCtx * outfile, int quality)
if (im->trueColor) {
#if BITS_IN_JSAMPLE == 12
php_gd_error("gd-jpeg: error: jpeg library was compiled for 12-bit precision. This is mostly useless, because JPEGs on the web are 8-bit and such versions of the jpeg library won't read or write them. GD doesn't support these unusual images. Edit your jmorecfg.h file to specify the correct precision and completely 'make clean' and 'make install' libjpeg again. Sorry");
gd_error("gd-jpeg: error: jpeg library was compiled for 12-bit precision. This is mostly useless, because JPEGs on the web are 8-bit and such versions of the jpeg library won't read or write them. GD doesn't support these unusual images. Edit your jmorecfg.h file to specify the correct precision and completely 'make clean' and 'make install' libjpeg again. Sorry");
goto error;
#endif /* BITS_IN_JSAMPLE == 12 */
@ -241,7 +242,7 @@ void gdImageJpegCtx (gdImagePtr im, gdIOCtx * outfile, int quality)
nlines = jpeg_write_scanlines (&cinfo, rowptr, 1);
if (nlines != 1) {
php_gd_error_ex(E_WARNING, "gd_jpeg: warning: jpeg_write_scanlines returns %u -- expected 1", nlines);
gd_error_ex(GD_WARNING, "gd_jpeg: warning: jpeg_write_scanlines returns %u -- expected 1", nlines);
}
}
} else {
@ -268,7 +269,7 @@ void gdImageJpegCtx (gdImagePtr im, gdIOCtx * outfile, int quality)
nlines = jpeg_write_scanlines (&cinfo, rowptr, 1);
if (nlines != 1) {
php_gd_error_ex(E_WARNING, "gd_jpeg: warning: jpeg_write_scanlines returns %u -- expected 1", nlines);
gd_error_ex(GD_WARNING, "gd_jpeg: warning: jpeg_write_scanlines returns %u -- expected 1", nlines);
}
}
}
@ -369,20 +370,20 @@ gdImagePtr gdImageCreateFromJpegCtxEx (gdIOCtx * infile, int ignore_warning)
retval = jpeg_read_header (&cinfo, TRUE);
if (retval != JPEG_HEADER_OK) {
php_gd_error_ex(E_WARNING, "gd-jpeg: warning: jpeg_read_header returned %d, expected %d", retval, JPEG_HEADER_OK);
gd_error_ex(GD_WARNING, "gd-jpeg: warning: jpeg_read_header returned %d, expected %d", retval, JPEG_HEADER_OK);
}
if (cinfo.image_height > INT_MAX) {
php_gd_error_ex(E_WARNING, "gd-jpeg: warning: JPEG image height (%u) is greater than INT_MAX (%d) (and thus greater than gd can handle)", cinfo.image_height, INT_MAX);
gd_error_ex(GD_WARNING, "gd-jpeg: warning: JPEG image height (%u) is greater than INT_MAX (%d) (and thus greater than gd can handle)", cinfo.image_height, INT_MAX);
}
if (cinfo.image_width > INT_MAX) {
php_gd_error_ex(E_WARNING, "gd-jpeg: warning: JPEG image width (%u) is greater than INT_MAX (%d) (and thus greater than gd can handle)", cinfo.image_width, INT_MAX);
gd_error_ex(GD_WARNING, "gd-jpeg: warning: JPEG image width (%u) is greater than INT_MAX (%d) (and thus greater than gd can handle)", cinfo.image_width, INT_MAX);
}
im = gdImageCreateTrueColor ((int) cinfo.image_width, (int) cinfo.image_height);
if (im == 0) {
php_gd_error("gd-jpeg error: cannot allocate gdImage struct");
gd_error("gd-jpeg error: cannot allocate gdImage struct");
goto error;
}
@ -408,7 +409,7 @@ gdImagePtr gdImageCreateFromJpegCtxEx (gdIOCtx * infile, int ignore_warning)
}
if (jpeg_start_decompress (&cinfo) != TRUE) {
php_gd_error("gd-jpeg: warning: jpeg_start_decompress reports suspended data source");
gd_error("gd-jpeg: warning: jpeg_start_decompress reports suspended data source");
}
/* REMOVED by TBB 2/12/01. This field of the structure is
@ -426,14 +427,14 @@ gdImagePtr gdImageCreateFromJpegCtxEx (gdIOCtx * infile, int ignore_warning)
if (cinfo.out_color_space == JCS_RGB) {
if (cinfo.output_components != 3) {
php_gd_error_ex(E_WARNING, "gd-jpeg: error: JPEG color quantization request resulted in output_components == %d (expected 3 for RGB)", cinfo.output_components);
gd_error_ex(GD_WARNING, "gd-jpeg: error: JPEG color quantization request resulted in output_components == %d (expected 3 for RGB)", cinfo.output_components);
goto error;
}
channels = 3;
} else if (cinfo.out_color_space == JCS_CMYK) {
jpeg_saved_marker_ptr marker;
if (cinfo.output_components != 4) {
php_gd_error_ex(E_WARNING, "gd-jpeg: error: JPEG color quantization request resulted in output_components == %d (expected 4 for CMYK)", cinfo.output_components);
gd_error_ex(GD_WARNING, "gd-jpeg: error: JPEG color quantization request resulted in output_components == %d (expected 4 for CMYK)", cinfo.output_components);
goto error;
}
channels = 4;
@ -446,12 +447,12 @@ gdImagePtr gdImageCreateFromJpegCtxEx (gdIOCtx * infile, int ignore_warning)
marker = marker->next;
}
} else {
php_gd_error_ex(E_WARNING, "gd-jpeg: error: unexpected colorspace.");
gd_error_ex(GD_WARNING, "gd-jpeg: error: unexpected colorspace.");
goto error;
}
#if BITS_IN_JSAMPLE == 12
php_gd_error("gd-jpeg: error: jpeg library was compiled for 12-bit precision. This is mostly useless, because JPEGs on the web are 8-bit and such versions of the jpeg library won't read or write them. GD doesn't support these unusual images. Edit your jmorecfg.h file to specify the correct precision and completely 'make clean' and 'make install' libjpeg again. Sorry.");
gd_error("gd-jpeg: error: jpeg library was compiled for 12-bit precision. This is mostly useless, because JPEGs on the web are 8-bit and such versions of the jpeg library won't read or write them. GD doesn't support these unusual images. Edit your jmorecfg.h file to specify the correct precision and completely 'make clean' and 'make install' libjpeg again. Sorry.");
goto error;
#endif /* BITS_IN_JSAMPLE == 12 */
@ -465,7 +466,7 @@ gdImagePtr gdImageCreateFromJpegCtxEx (gdIOCtx * infile, int ignore_warning)
register int *tpix = im->tpixels[i];
nrows = jpeg_read_scanlines (&cinfo, rowptr, 1);
if (nrows != 1) {
php_gd_error_ex(E_WARNING, "gd-jpeg: error: jpeg_read_scanlines returns %u, expected 1", nrows);
gd_error_ex(GD_WARNING, "gd-jpeg: error: jpeg_read_scanlines returns %u, expected 1", nrows);
goto error;
}
for (j = 0; j < cinfo.output_width; j++, currow += 4, tpix++) {
@ -478,7 +479,7 @@ gdImagePtr gdImageCreateFromJpegCtxEx (gdIOCtx * infile, int ignore_warning)
register int *tpix = im->tpixels[i];
nrows = jpeg_read_scanlines (&cinfo, rowptr, 1);
if (nrows != 1) {
php_gd_error_ex(E_WARNING, "gd-jpeg: error: jpeg_read_scanlines returns %u, expected 1", nrows);
gd_error_ex(GD_WARNING, "gd-jpeg: error: jpeg_read_scanlines returns %u, expected 1", nrows);
goto error;
}
for (j = 0; j < cinfo.output_width; j++, currow += 3, tpix++) {
@ -488,7 +489,7 @@ gdImagePtr gdImageCreateFromJpegCtxEx (gdIOCtx * infile, int ignore_warning)
}
if (jpeg_finish_decompress (&cinfo) != TRUE) {
php_gd_error("gd-jpeg: warning: jpeg_finish_decompress reports suspended data source");
gd_error("gd-jpeg: warning: jpeg_finish_decompress reports suspended data source");
}
if (!ignore_warning) {
if (cinfo.err->num_warnings > 0) {

View File

@ -3,6 +3,7 @@
#include <string.h>
#include <stdlib.h>
#include "gd.h"
#include "gd_errors.h"
/* JCE: Arrange HAVE_LIBPNG so that it can be set in gd.h */
#ifdef HAVE_LIBPNG
@ -61,11 +62,11 @@ static void gdPngErrorHandler (png_structp png_ptr, png_const_charp msg)
* been defined.
*/
php_gd_error_ex(E_WARNING, "gd-png: fatal libpng error: %s", msg);
gd_error_ex(GD_WARNING, "gd-png: fatal libpng error: %s", msg);
jmpbuf_ptr = png_get_error_ptr (png_ptr);
if (jmpbuf_ptr == NULL) { /* we are completely hosed now */
php_gd_error_ex(E_ERROR, "gd-png: EXTREMELY fatal error: jmpbuf unrecoverable; terminating.");
gd_error_ex(GD_ERROR, "gd-png: EXTREMELY fatal error: jmpbuf unrecoverable; terminating.");
}
longjmp (jmpbuf_ptr->jmpbuf, 1);
@ -156,13 +157,13 @@ gdImagePtr gdImageCreateFromPngCtx (gdIOCtx * infile)
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
#endif
if (png_ptr == NULL) {
php_gd_error("gd-png error: cannot allocate libpng main struct");
gd_error("gd-png error: cannot allocate libpng main struct");
return NULL;
}
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL) {
php_gd_error("gd-png error: cannot allocate libpng info struct");
gd_error("gd-png error: cannot allocate libpng info struct");
png_destroy_read_struct (&png_ptr, NULL, NULL);
return NULL;
@ -178,7 +179,7 @@ gdImagePtr gdImageCreateFromPngCtx (gdIOCtx * infile)
*/
#ifdef PNG_SETJMP_SUPPORTED
if (setjmp(jbw.jmpbuf)) {
php_gd_error("gd-png error: setjmp returns error condition");
gd_error("gd-png error: setjmp returns error condition");
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return NULL;
@ -198,7 +199,7 @@ gdImagePtr gdImageCreateFromPngCtx (gdIOCtx * infile)
im = gdImageCreate((int) width, (int) height);
}
if (im == NULL) {
php_gd_error("gd-png error: cannot allocate gdImage struct");
gd_error("gd-png error: cannot allocate gdImage struct");
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return NULL;
@ -215,7 +216,7 @@ gdImagePtr gdImageCreateFromPngCtx (gdIOCtx * infile)
*/
#ifdef PNG_SETJMP_SUPPORTED
if (setjmp(jbw.jmpbuf)) {
php_gd_error("gd-png error: setjmp returns error condition");
gd_error("gd-png error: setjmp returns error condition");
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
gdFree(image_data);
gdFree(row_pointers);
@ -244,7 +245,7 @@ gdImagePtr gdImageCreateFromPngCtx (gdIOCtx * infile)
case PNG_COLOR_TYPE_PALETTE:
png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette);
#ifdef DEBUG
php_gd_error("gd-png color_type is palette, colors: %d", num_palette);
gd_error("gd-png color_type is palette, colors: %d", num_palette);
#endif /* DEBUG */
if (png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS)) {
/* gd 2.0: we support this rather thoroughly now. Grab the
@ -267,7 +268,7 @@ gdImagePtr gdImageCreateFromPngCtx (gdIOCtx * infile)
case PNG_COLOR_TYPE_GRAY:
/* create a fake palette and check for single-shade transparency */
if ((palette = (png_colorp) gdMalloc (256 * sizeof (png_color))) == NULL) {
php_gd_error("gd-png error: cannot allocate gray palette");
gd_error("gd-png error: cannot allocate gray palette");
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return NULL;
@ -416,7 +417,7 @@ gdImagePtr gdImageCreateFromPngCtx (gdIOCtx * infile)
if (!im->trueColor) {
for (i = num_palette; i < gdMaxColors; ++i) {
if (!open[i]) {
php_gd_error("gd-png warning: image data references out-of-range color index (%d)", i);
gd_error("gd-png warning: image data references out-of-range color index (%d)", i);
}
}
}
@ -498,13 +499,13 @@ void gdImagePngCtxEx (gdImagePtr im, gdIOCtx * outfile, int level, int basefilte
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
#endif
if (png_ptr == NULL) {
php_gd_error("gd-png error: cannot allocate libpng main struct");
gd_error("gd-png error: cannot allocate libpng main struct");
return;
}
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL) {
php_gd_error("gd-png error: cannot allocate libpng info struct");
gd_error("gd-png error: cannot allocate libpng info struct");
png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
return;
@ -512,7 +513,7 @@ void gdImagePngCtxEx (gdImagePtr im, gdIOCtx * outfile, int level, int basefilte
#ifdef PNG_SETJMP_SUPPORTED
if (setjmp(jbw.jmpbuf)) {
php_gd_error("gd-png error: setjmp returns error condition");
gd_error("gd-png error: setjmp returns error condition");
png_destroy_write_struct (&png_ptr, &info_ptr);
return;
@ -532,7 +533,7 @@ void gdImagePngCtxEx (gdImagePtr im, gdIOCtx * outfile, int level, int basefilte
/* 2.0.12: this is finally a parameter */
if (level != -1 && (level < 0 || level > 9)) {
php_gd_error("gd-png error: compression level must be 0 through 9");
gd_error("gd-png error: compression level must be 0 through 9");
return;
}
png_set_compression_level(png_ptr, level);
@ -570,7 +571,7 @@ void gdImagePngCtxEx (gdImagePtr im, gdIOCtx * outfile, int level, int basefilte
}
}
if (colors == 0) {
php_gd_error("gd-png error: no colors in palette");
gd_error("gd-png error: no colors in palette");
goto bail;
}
if (colors < im->colorsTotal) {

View File

@ -20,11 +20,11 @@
int overflow2(int a, int b)
{
if(a <= 0 || b <= 0) {
php_gd_error("gd warning: one parameter to a memory allocation multiplication is negative or zero, failing operation gracefully\n");
gd_error("gd warning: one parameter to a memory allocation multiplication is negative or zero, failing operation gracefully\n");
return 1;
}
if(a > INT_MAX / b) {
php_gd_error("gd warning: product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully\n");
gd_error("gd warning: product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully\n");
return 1;
}
return 0;

View File

@ -38,11 +38,11 @@ gdImagePtr gdImageCreateFromPngSource (gdSourcePtr inSource)
#else /* no HAVE_LIBPNG */
void gdImagePngToSink (gdImagePtr im, gdSinkPtr outSink)
{
php_gd_error("PNG support is not available");
gd_error("PNG support is not available");
}
gdImagePtr gdImageCreateFromPngSource (gdSourcePtr inSource)
{
php_gd_error("PNG support is not available");
gd_error("PNG support is not available");
return NULL;
}
#endif /* HAVE_LIBPNG */

View File

@ -98,7 +98,7 @@ void gdImageWBMPCtx (gdImagePtr image, int fg, gdIOCtx * out)
/* create the WBMP */
if ((wbmp = createwbmp (gdImageSX (image), gdImageSY (image), WBMP_WHITE)) == NULL) {
php_gd_error("Could not create WBMP");
gd_error("Could not create WBMP");
}
/* fill up the WBMP structure */
@ -114,7 +114,7 @@ void gdImageWBMPCtx (gdImagePtr image, int fg, gdIOCtx * out)
/* write the WBMP to a gd file descriptor */
if (writewbmp (wbmp, &gd_putout, out)) {
php_gd_error("Could not save WBMP");
gd_error("Could not save WBMP");
}
/* des submitted this bugfix: gdFree the memory. */
freewbmp(wbmp);

View File

@ -149,7 +149,7 @@ gdImagePtr gdImageCreateFromXbm(FILE * fd)
}
}
php_gd_error("EOF before image was complete");
gd_error("EOF before image was complete");
gdImageDestroy(im);
return 0;
}