From e36e62d51a412a78a69f82e101018ab083bd5e40 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Wed, 30 Mar 2022 20:30:34 -0700 Subject: [PATCH] webp_format: squash -Wsign-conversion warnings --- plugin/webp/gvdevice_webp.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/plugin/webp/gvdevice_webp.c b/plugin/webp/gvdevice_webp.c index 4331a8229..6bded0c76 100644 --- a/plugin/webp/gvdevice_webp.c +++ b/plugin/webp/gvdevice_webp.c @@ -55,9 +55,17 @@ static void webp_format(GVJ_t * job) goto Error; } - picture.width = job->width; - picture.height = job->height; - stride = 4 * job->width; + // if either dimension exceeds the WebP API, map this to one of its errors + if ((unsigned)INT_MAX / 4 < job->width || job->height > (unsigned)INT_MAX) { + int error = VP8_ENC_ERROR_BAD_DIMENSION; + fprintf(stderr, "Error! Cannot encode picture as WebP\n"); + fprintf(stderr, "Error code: %d (%s)\n", error, kErrorMessages[error]); + goto Error; + } + + picture.width = (int)job->width; + picture.height = (int)job->height; + stride = 4 * (int)job->width; picture.writer = writer; picture.custom_ptr = job; -- 2.40.0