diff --git a/image-kitty.c b/image-kitty.c index 572ef856b..ae41189b5 100644 --- a/image-kitty.c +++ b/image-kitty.c @@ -431,7 +431,7 @@ kitty_upload(struct tty *tty, struct image *im) return (NULL); upload_width = canvas_width + 2; upload_height = canvas_height + 2; - if ((uint64_t)upload_width * upload_height * 4 > IMAGE_SIZE_LIMIT) + if ((uint64_t)upload_width * upload_height > IMAGE_SIZE_LIMIT / 4) return (NULL); for (entry = ko->images; entry != NULL; entry = entry->next) { diff --git a/image.c b/image.c index 947c5ea33..0b4735404 100644 --- a/image.c +++ b/image.c @@ -966,7 +966,7 @@ image_create(u_int width, u_int height, u_int canvas_width, if (width == 0 || height == 0 || canvas_width < width || canvas_height < height || sx == 0 || sy == 0 || pixels == NULL) return (NULL); - if ((uint64_t)width * height * 4 > SIZE_MAX) + if ((uint64_t)width * height > SIZE_MAX / 4) return (NULL); if ((uint64_t)sx * sy > SIZE_MAX / sizeof *im->cells || sx > USHRT_MAX || sy > USHRT_MAX)