diff --git a/source/convert_to_argb.cc b/source/convert_to_argb.cc index 720cb0984..f3c4018d7 100644 --- a/source/convert_to_argb.cc +++ b/source/convert_to_argb.cc @@ -92,9 +92,11 @@ int ConvertToARGB(const uint8_t* sample, if (need_buf) { const uint64_t rotate_buffer_size = (uint64_t)crop_width * 4 * abs_crop_height; +#if UINT64_MAX > SIZE_MAX if (rotate_buffer_size > SIZE_MAX) { return -1; // Invalid size. } +#endif rotate_buffer = (uint8_t*)malloc((size_t)rotate_buffer_size); if (!rotate_buffer) { return 1; // Out of memory runtime error. diff --git a/source/scale_argb.cc b/source/scale_argb.cc index 4dc446d5e..8758d79c2 100644 --- a/source/scale_argb.cc +++ b/source/scale_argb.cc @@ -844,9 +844,11 @@ int YUVToARGBScaleClip(const uint8_t* src_y, } const int abs_src_height = (src_height < 0) ? -src_height : src_height; const uint64_t argb_buffer_size = (uint64_t)src_width * abs_src_height * 4; +#if UINT64_MAX > SIZE_MAX if (argb_buffer_size > SIZE_MAX) { return -1; // Invalid size. } +#endif uint8_t* argb_buffer = (uint8_t*)malloc((size_t)argb_buffer_size); if (!argb_buffer) { return 1; // Out of memory runtime error. diff --git a/source/scale_rgb.cc b/source/scale_rgb.cc index 6040b364e..0a2f2f6b9 100644 --- a/source/scale_rgb.cc +++ b/source/scale_rgb.cc @@ -53,9 +53,11 @@ int RGBScale(const uint8_t* src_rgb, return -1; // Invalid size. } const uint64_t argb_size = src_argb_size + dst_argb_size; +#if UINT64_MAX > SIZE_MAX if (argb_size > SIZE_MAX) { return -1; // Invalid size. } +#endif uint8_t* src_argb = (uint8_t*)malloc((size_t)argb_size); if (!src_argb) { return 1; // Out of memory runtime error.