mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-27 06:08:21 +01:00
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
This commit is contained in:
parent
28d488e6f1
commit
c9e26bdb35
@ -12,6 +12,7 @@
|
|||||||
// Author: Skal (pascal.massimino@gmail.com)
|
// Author: Skal (pascal.massimino@gmail.com)
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "src/dsp/dsp.h"
|
#include "src/dsp/dsp.h"
|
||||||
@ -83,6 +84,7 @@ int WebPRescalerGetScaledDimensions(int src_width, int src_height,
|
|||||||
{
|
{
|
||||||
int width = *scaled_width;
|
int width = *scaled_width;
|
||||||
int height = *scaled_height;
|
int height = *scaled_height;
|
||||||
|
const int max_size = INT_MAX / 2;
|
||||||
|
|
||||||
// if width is unspecified, scale original proportionally to height ratio.
|
// if width is unspecified, scale original proportionally to height ratio.
|
||||||
if (width == 0 && src_height > 0) {
|
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);
|
(int)(((uint64_t)src_height * width + src_width - 1) / src_width);
|
||||||
}
|
}
|
||||||
// Check if the overall dimensions still make sense.
|
// 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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user