Skip to content

Commit 089f7c0

Browse files
committed
Sync with upstream
Even though libgd/libgd#492 is not a relevant bug fix for PHP, since the binding doesn't use the `gdImage*Ptr()` functions at all, we're porting the fix to stay in sync here.
1 parent 6aff4d0 commit 089f7c0

File tree

3 files changed

+46
-9
lines changed

3 files changed

+46
-9
lines changed

Diff for: ext/gd/libgd/gd_gif_out.c

+17-3
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,18 @@ static void cl_hash (register count_int chsize, GifCtx *ctx);
9797
static void char_init (GifCtx *ctx);
9898
static void char_out (int c, GifCtx *ctx);
9999
static void flush_char (GifCtx *ctx);
100+
101+
static int _gdImageGifCtx(gdImagePtr im, gdIOCtxPtr out);
102+
100103
void * gdImageGifPtr (gdImagePtr im, int *size)
101104
{
102105
void *rv;
103106
gdIOCtx *out = gdNewDynamicCtx (2048, NULL);
104-
gdImageGifCtx (im, out);
105-
rv = gdDPExtractData (out, size);
107+
if (!_gdImageGifCtx(im, out)) {
108+
rv = gdDPExtractData(out, size);
109+
} else {
110+
rv = NULL;
111+
}
106112
out->gd_free (out);
107113
return rv;
108114
}
@@ -115,6 +121,12 @@ void gdImageGif (gdImagePtr im, FILE * outFile)
115121
}
116122

117123
void gdImageGifCtx(gdImagePtr im, gdIOCtxPtr out)
124+
{
125+
_gdImageGifCtx(im, out);
126+
}
127+
128+
/* returns 0 on success, 1 on failure */
129+
static int _gdImageGifCtx(gdImagePtr im, gdIOCtxPtr out)
118130
{
119131
gdImagePtr pim = 0, tim = im;
120132
int interlace, BitsPerPixel;
@@ -125,7 +137,7 @@ void gdImageGifCtx(gdImagePtr im, gdIOCtxPtr out)
125137
based temporary image. */
126138
pim = gdImageCreatePaletteFromTrueColor(im, 1, 256);
127139
if (!pim) {
128-
return;
140+
return 1;
129141
}
130142
tim = pim;
131143
}
@@ -138,6 +150,8 @@ void gdImageGifCtx(gdImagePtr im, gdIOCtxPtr out)
138150
/* Destroy palette based temporary image. */
139151
gdImageDestroy( pim);
140152
}
153+
154+
return 0;
141155
}
142156

143157
static int

Diff for: ext/gd/libgd/gd_jpeg.c

+14-3
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ const char * gdJpegGetVersionString()
132132
}
133133
}
134134

135+
static int _gdImageJpegCtx(gdImagePtr im, gdIOCtx *outfile, int quality);
135136

136137
/*
137138
* Write IM to OUTFILE as a JFIF-formatted JPEG image, using quality
@@ -153,8 +154,11 @@ void *gdImageJpegPtr (gdImagePtr im, int *size, int quality)
153154
{
154155
void *rv;
155156
gdIOCtx *out = gdNewDynamicCtx (2048, NULL);
156-
gdImageJpegCtx (im, out, quality);
157-
rv = gdDPExtractData (out, size);
157+
if (!_gdImageJpegCtx(im, out, quality)) {
158+
rv = gdDPExtractData(out, size);
159+
} else {
160+
rv = NULL;
161+
}
158162
out->gd_free (out);
159163

160164
return rv;
@@ -163,6 +167,12 @@ void *gdImageJpegPtr (gdImagePtr im, int *size, int quality)
163167
void jpeg_gdIOCtx_dest (j_compress_ptr cinfo, gdIOCtx * outfile);
164168

165169
void gdImageJpegCtx (gdImagePtr im, gdIOCtx * outfile, int quality)
170+
{
171+
_gdImageJpegCtx(im, outfile, quality);
172+
}
173+
174+
/* returns 0 on success, 1 on failure */
175+
static int _gdImageJpegCtx(gdImagePtr im, gdIOCtx *outfile, int quality)
166176
{
167177
struct jpeg_compress_struct cinfo;
168178
struct jpeg_error_mgr jerr;
@@ -184,7 +194,7 @@ void gdImageJpegCtx (gdImagePtr im, gdIOCtx * outfile, int quality)
184194
if (row) {
185195
gdFree (row);
186196
}
187-
return;
197+
return 1;
188198
}
189199

190200
cinfo.err->error_exit = fatal_jpeg_error;
@@ -277,6 +287,7 @@ void gdImageJpegCtx (gdImagePtr im, gdIOCtx * outfile, int quality)
277287
jpeg_finish_compress (&cinfo);
278288
jpeg_destroy_compress (&cinfo);
279289
gdFree (row);
290+
return 0;
280291
}
281292

282293
gdImagePtr gdImageCreateFromJpeg (FILE * inFile)

Diff for: ext/gd/libgd/gd_wbmp.c

+15-3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ int gd_getin (void *in)
8282
return (gdGetC((gdIOCtx *) in));
8383
}
8484

85+
static int _gdImageWBMPCtx(gdImagePtr image, int fg, gdIOCtx *out);
8586

8687
/* gdImageWBMPCtx
8788
** --------------
@@ -93,14 +94,20 @@ int gd_getin (void *in)
9394
** out: the stream where to write
9495
*/
9596
void gdImageWBMPCtx (gdImagePtr image, int fg, gdIOCtx * out)
97+
{
98+
_gdImageWBMPCtx(image, fg, out);
99+
}
100+
101+
/* returns 0 on success, 1 on failure */
102+
static int _gdImageWBMPCtx(gdImagePtr image, int fg, gdIOCtx *out)
96103
{
97104
int x, y, pos;
98105
Wbmp *wbmp;
99106

100107
/* create the WBMP */
101108
if ((wbmp = createwbmp (gdImageSX (image), gdImageSY (image), WBMP_WHITE)) == NULL) {
102109
gd_error("Could not create WBMP");
103-
return;
110+
return 1;
104111
}
105112

106113
/* fill up the WBMP structure */
@@ -116,7 +123,9 @@ void gdImageWBMPCtx (gdImagePtr image, int fg, gdIOCtx * out)
116123

117124
/* write the WBMP to a gd file descriptor */
118125
if (writewbmp (wbmp, &gd_putout, out)) {
126+
freewbmp(wbmp);
119127
gd_error("Could not save WBMP");
128+
return 1;
120129
}
121130
/* des submitted this bugfix: gdFree the memory. */
122131
freewbmp(wbmp);
@@ -204,8 +213,11 @@ void * gdImageWBMPPtr (gdImagePtr im, int *size, int fg)
204213
{
205214
void *rv;
206215
gdIOCtx *out = gdNewDynamicCtx(2048, NULL);
207-
gdImageWBMPCtx(im, fg, out);
208-
rv = gdDPExtractData(out, size);
216+
if (!_gdImageWBMPCtx(im, fg, out)) {
217+
rv = gdDPExtractData(out, size);
218+
} else {
219+
rv = NULL;
220+
}
209221
out->gd_free(out);
210222

211223
return rv;

0 commit comments

Comments
 (0)