Skip to content

Backport libgd commit #7296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions ext/gd/libgd/gd_avif.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ static avifBool isAvifSrgbImage(avifImage *avifIm) {
*/
static avifBool isAvifError(avifResult result, const char *msg) {
if (result != AVIF_RESULT_OK) {
gd_error("avif error - %s: %s", msg, avifResultToString(result));
gd_error("avif error - %s: %s\n", msg, avifResultToString(result));
return AVIF_TRUE;
}

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

// readFlags is unsupported
if (readFlags != 0) {
return AVIF_RESULT_IO_ERROR;
}

// TODO: if we set sizeHint, this will be more efficient.

if (offset > LONG_MAX || size < 0)
if (offset > INT_MAX || size > INT_MAX)
return AVIF_RESULT_IO_ERROR;

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

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

// Read the number of bytes requested.
// If getBuf() returns a negative value, that means there was an error.
int charsRead = ctx->getBuf(ctx, dataBuf, size);
int charsRead = ctx->getBuf(ctx, dataBuf, (int) size);
if (charsRead < 0) {
avifFree(dataBuf);
return AVIF_RESULT_IO_ERROR;
Expand Down Expand Up @@ -330,7 +335,7 @@ gdImagePtr gdImageCreateFromAvifPtr(int size, void *data)
*/
gdImagePtr gdImageCreateFromAvifCtx (gdIOCtx *ctx)
{
int x, y;
uint32_t x, y;
gdImage *im = NULL;
avifResult result;
avifIO *io;
Expand Down Expand Up @@ -465,7 +470,7 @@ void gdImageAvifCtx(gdImagePtr im, gdIOCtx *outfile, int quality, int speed)

uint32_t val;
uint8_t *p;
int x, y;
uint32_t x, y;

if (im == NULL)
return;
Expand Down