Fix for libavif v0.8.2 (#680)

Don't return AVIF_RESULT_TRUNCATED_DATA, as this is normal for libavif <= 0.8.2. In our tests,
this makes tests pass with libavif 0.8.2.

Plus, we did a few things to stop compiler warnings - and added a newline to error output.

thanks @wantehchang for the collaboration here!

This fixes #677.
master
Ben Morss 2021-03-16 12:26:17 -04:00 committed by GitHub
parent 5b63349b82
commit f6a111c632
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 7 deletions

View File

@ -151,7 +151,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;
}
@ -177,13 +177,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 = gdMalloc(size);
@ -194,7 +199,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) {
gdFree(dataBuf);
return AVIF_RESULT_IO_ERROR;
@ -202,7 +207,7 @@ static avifResult readFromCtx(avifIO *io, uint32_t readFlags, uint64_t offset, s
out->data = dataBuf;
out->size = charsRead;
return charsRead == size ? AVIF_RESULT_OK : AVIF_RESULT_TRUNCATED_DATA;
return AVIF_RESULT_OK;
}
// avif.h says this is optional, but it seemed easy to implement.
@ -339,7 +344,7 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromAvifPtr(int size, void *data)
*/
BGD_DECLARE(gdImagePtr) gdImageCreateFromAvifCtx (gdIOCtx *ctx)
{
int x, y;
uint32_t x, y;
gdImage *im = NULL;
avifResult result;
avifIO *io;
@ -482,7 +487,7 @@ static avifBool _gdImageAvifCtx(gdImagePtr im, gdIOCtx *outfile, int quality, in
uint32_t val;
uint8_t *p;
int x, y;
uint32_t x, y;
if (im == NULL)
return 1;