aboutsummaryrefslogtreecommitdiff
path: root/source/scale_argb.cc
diff options
context:
space:
mode:
authorFrank Barchard <fbarchard@google.com>2023-10-27 10:12:13 -0700
committerlibyuv LUCI CQ <libyuv-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-10-27 17:41:36 +0000
commit31e1d6f896615342d5d5b6bde8f7b50b3fd698dc (patch)
tree685ffd3182496e78e4e23c45fdd3729501cca38c /source/scale_argb.cc
parent331c361581896292fb46c8c6905e41262b7ca95f (diff)
downloadlibyuv-31e1d6f896615342d5d5b6bde8f7b50b3fd698dc.tar.gz
Check allocations that return NULL and return early
BUG=libyuv:968 Change-Id: I9e8594440a6035958511f9c50072820131331fc8 Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/4977552 Reviewed-by: Wan-Teh Chang <wtc@google.com> Commit-Queue: Frank Barchard <fbarchard@chromium.org>
Diffstat (limited to 'source/scale_argb.cc')
-rw-r--r--source/scale_argb.cc10
1 files changed, 9 insertions, 1 deletions
diff --git a/source/scale_argb.cc b/source/scale_argb.cc
index 1d5c1b60..fa35b0c9 100644
--- a/source/scale_argb.cc
+++ b/source/scale_argb.cc
@@ -167,6 +167,7 @@ static void ScaleARGBDown4Box(int src_width,
// Allocate 2 rows of ARGB.
const int row_size = (dst_width * 2 * 4 + 31) & ~31;
align_buffer_64(row, row_size * 2);
+ if (!row) return;
int row_stride = src_stride * (dy >> 16);
void (*ScaleARGBRowDown2)(const uint8_t* src_argb, ptrdiff_t src_stride,
uint8_t* dst_argb, int dst_width) =
@@ -407,6 +408,7 @@ static void ScaleARGBBilinearDown(int src_width,
// Allocate a row of ARGB.
{
align_buffer_64(row, clip_src_width * 4);
+ if (!row) return;
const int max_y = (src_height - 1) << 16;
if (y > max_y) {
@@ -581,6 +583,7 @@ static void ScaleARGBBilinearUp(int src_width,
// Allocate 2 rows of ARGB.
const int row_size = (dst_width * 4 + 31) & ~31;
align_buffer_64(row, row_size * 2);
+ if (!row) return;
uint8_t* rowptr = row;
int rowstride = row_size;
@@ -849,9 +852,11 @@ static void ScaleYUVToARGBBilinearUp(int src_width,
// Allocate 2 rows of ARGB.
const int row_size = (dst_width * 4 + 31) & ~31;
align_buffer_64(row, row_size * 2);
+ if (!row) return;
// Allocate 1 row of ARGB for source conversion.
align_buffer_64(argb_row, src_width * 4);
+ if (!argb_row) return;
uint8_t* rowptr = row;
int rowstride = row_size;
@@ -1158,8 +1163,11 @@ int YUVToARGBScaleClip(const uint8_t* src_y,
int clip_width,
int clip_height,
enum FilterMode filtering) {
- uint8_t* argb_buffer = (uint8_t*)malloc(src_width * src_height * 4);
int r;
+ uint8_t* argb_buffer = (uint8_t*)malloc(src_width * src_height * 4);
+ if (!argb_buffer) {
+ return 1; // Out of memory runtime error.
+ }
(void)src_fourcc; // TODO(fbarchard): implement and/or assert.
(void)dst_fourcc;
I420ToARGB(src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v,