diff options
author | James Zern <jzern@google.com> | 2021-06-14 12:20:45 -0700 |
---|---|---|
committer | James Zern <jzern@google.com> | 2021-06-14 12:22:28 -0700 |
commit | c9e26bdb35723159146006d129638c40eab9d5c7 (patch) | |
tree | e39026ebbf31ddd3fdb38a07b633dbc33bd07600 | |
parent | 28d488e6f10310fa79cad2b7e26296d6341f43ea (diff) | |
download | libwebp-c9e26bdb35723159146006d129638c40eab9d5c7.tar.gz |
rescaler_utils: set max valid scaled w/h to INT_MAX/2
this will avoid the potential for some integer overflows in rescaler
calculations
Bug: chromium:1196850
Change-Id: Iaa09f5d6b888b39aaeb2154d470279620362d6eb
-rw-r--r-- | src/utils/rescaler_utils.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/utils/rescaler_utils.c b/src/utils/rescaler_utils.c index a4e80953..2f8c4979 100644 --- a/src/utils/rescaler_utils.c +++ b/src/utils/rescaler_utils.c @@ -12,6 +12,7 @@ // Author: Skal (pascal.massimino@gmail.com) #include <assert.h> +#include <limits.h> #include <stdlib.h> #include <string.h> #include "src/dsp/dsp.h" @@ -83,6 +84,7 @@ int WebPRescalerGetScaledDimensions(int src_width, int src_height, { int width = *scaled_width; int height = *scaled_height; + const int max_size = INT_MAX / 2; // if width is unspecified, scale original proportionally to height ratio. if (width == 0 && src_height > 0) { @@ -95,7 +97,7 @@ int WebPRescalerGetScaledDimensions(int src_width, int src_height, (int)(((uint64_t)src_height * width + src_width - 1) / src_width); } // Check if the overall dimensions still make sense. - if (width <= 0 || height <= 0) { + if (width <= 0 || height <= 0 || width > max_size || height > max_size) { return 0; } |