Skip to content

Commit bb9ef2b

Browse files
andypostnikic
authored andcommitted
Backport libgd commit
Source - libgd/libgd@f6a111c Related to php#5127 (comment)
1 parent 9e787d5 commit bb9ef2b

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

ext/gd/libgd/gd_avif.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ static avifBool isAvifSrgbImage(avifImage *avifIm) {
142142
*/
143143
static avifBool isAvifError(avifResult result, const char *msg) {
144144
if (result != AVIF_RESULT_OK) {
145-
gd_error("avif error - %s: %s", msg, avifResultToString(result));
145+
gd_error("avif error - %s: %s\n", msg, avifResultToString(result));
146146
return AVIF_TRUE;
147147
}
148148

@@ -168,13 +168,18 @@ static avifResult readFromCtx(avifIO *io, uint32_t readFlags, uint64_t offset, s
168168
void *dataBuf = NULL;
169169
gdIOCtx *ctx = (gdIOCtx *) io->data;
170170

171+
// readFlags is unsupported
172+
if (readFlags != 0) {
173+
return AVIF_RESULT_IO_ERROR;
174+
}
175+
171176
// TODO: if we set sizeHint, this will be more efficient.
172177

173-
if (offset > LONG_MAX || size < 0)
178+
if (offset > INT_MAX || size > INT_MAX)
174179
return AVIF_RESULT_IO_ERROR;
175180

176181
// Try to seek offset bytes forward. If we pass the end of the buffer, throw an error.
177-
if (!ctx->seek(ctx, offset))
182+
if (!ctx->seek(ctx, (int) offset))
178183
return AVIF_RESULT_IO_ERROR;
179184

180185
dataBuf = avifAlloc(size);
@@ -185,7 +190,7 @@ static avifResult readFromCtx(avifIO *io, uint32_t readFlags, uint64_t offset, s
185190

186191
// Read the number of bytes requested.
187192
// If getBuf() returns a negative value, that means there was an error.
188-
int charsRead = ctx->getBuf(ctx, dataBuf, size);
193+
int charsRead = ctx->getBuf(ctx, dataBuf, (int) size);
189194
if (charsRead < 0) {
190195
avifFree(dataBuf);
191196
return AVIF_RESULT_IO_ERROR;
@@ -330,7 +335,7 @@ gdImagePtr gdImageCreateFromAvifPtr(int size, void *data)
330335
*/
331336
gdImagePtr gdImageCreateFromAvifCtx (gdIOCtx *ctx)
332337
{
333-
int x, y;
338+
uint32_t x, y;
334339
gdImage *im = NULL;
335340
avifResult result;
336341
avifIO *io;
@@ -465,7 +470,7 @@ void gdImageAvifCtx(gdImagePtr im, gdIOCtx *outfile, int quality, int speed)
465470

466471
uint32_t val;
467472
uint8_t *p;
468-
int x, y;
473+
uint32_t x, y;
469474

470475
if (im == NULL)
471476
return;

0 commit comments

Comments
 (0)