mirror of
https://github.com/webmproject/libwebp.git
synced 2025-07-13 06:24:27 +02:00
imageio_util: add ImgIoUtilCheckSizeArgumentsOverflow
and use it to validate decoder allocations. fixes a crash in jpegdec at least. BUG=webp:312 Change-Id: Ia940590098f29510add6aad10a8dfe9e9ea46bf4
This commit is contained in:
@ -25,6 +25,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "webp/encode.h"
|
||||
#include "./imageio_util.h"
|
||||
#include "./metadata.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -257,7 +258,8 @@ int ReadJPEG(const uint8_t* const data, size_t data_size,
|
||||
WebPPicture* const pic, int keep_alpha,
|
||||
Metadata* const metadata) {
|
||||
volatile int ok = 0;
|
||||
int stride, width, height;
|
||||
int width, height;
|
||||
int64_t stride;
|
||||
volatile struct jpeg_decompress_struct dinfo;
|
||||
struct my_error_mgr jerr;
|
||||
uint8_t* volatile rgb = NULL;
|
||||
@ -296,9 +298,14 @@ int ReadJPEG(const uint8_t* const data, size_t data_size,
|
||||
|
||||
width = dinfo.output_width;
|
||||
height = dinfo.output_height;
|
||||
stride = dinfo.output_width * dinfo.output_components * sizeof(*rgb);
|
||||
stride = (int64_t)dinfo.output_width * dinfo.output_components * sizeof(*rgb);
|
||||
|
||||
rgb = (uint8_t*)malloc(stride * height);
|
||||
if (stride != (int)stride ||
|
||||
!ImgIoUtilCheckSizeArgumentsOverflow(stride, height)) {
|
||||
goto End;
|
||||
}
|
||||
|
||||
rgb = (uint8_t*)malloc((size_t)stride * height);
|
||||
if (rgb == NULL) {
|
||||
goto End;
|
||||
}
|
||||
@ -325,7 +332,7 @@ int ReadJPEG(const uint8_t* const data, size_t data_size,
|
||||
// WebP conversion.
|
||||
pic->width = width;
|
||||
pic->height = height;
|
||||
ok = WebPPictureImportRGB(pic, rgb, stride);
|
||||
ok = WebPPictureImportRGB(pic, rgb, (int)stride);
|
||||
if (!ok) goto Error;
|
||||
|
||||
End:
|
||||
|
Reference in New Issue
Block a user