diff options
author | Frank Barchard <fbarchard@google.com> | 2023-10-27 10:12:13 -0700 |
---|---|---|
committer | libyuv LUCI CQ <libyuv-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-10-27 17:41:36 +0000 |
commit | 31e1d6f896615342d5d5b6bde8f7b50b3fd698dc (patch) | |
tree | 685ffd3182496e78e4e23c45fdd3729501cca38c | |
parent | 331c361581896292fb46c8c6905e41262b7ca95f (diff) | |
download | libyuv-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>
-rw-r--r-- | README.chromium | 2 | ||||
-rw-r--r-- | include/libyuv/row.h | 8 | ||||
-rw-r--r-- | include/libyuv/version.h | 2 | ||||
-rw-r--r-- | source/convert.cc | 10 | ||||
-rw-r--r-- | source/convert_argb.cc | 18 | ||||
-rw-r--r-- | source/convert_from_argb.cc | 8 | ||||
-rw-r--r-- | source/planar_functions.cc | 4 | ||||
-rw-r--r-- | source/rotate.cc | 11 | ||||
-rw-r--r-- | source/rotate_argb.cc | 1 | ||||
-rw-r--r-- | source/scale.cc | 6 | ||||
-rw-r--r-- | source/scale_argb.cc | 10 | ||||
-rw-r--r-- | source/scale_uv.cc | 3 |
12 files changed, 68 insertions, 15 deletions
diff --git a/README.chromium b/README.chromium index 8c340614..1c41d7d0 100644 --- a/README.chromium +++ b/README.chromium @@ -1,6 +1,6 @@ Name: libyuv URL: https://chromium.googlesource.com/libyuv/libyuv/ -Version: 1878 +Version: 1879 License: BSD License File: LICENSE Shipped: yes diff --git a/include/libyuv/row.h b/include/libyuv/row.h index 36561d6e..46685a50 100644 --- a/include/libyuv/row.h +++ b/include/libyuv/row.h @@ -949,14 +949,6 @@ struct YuvConstants { free(var##_mem); \ var = NULL -#define align_buffer_64_16(var, size) \ - void* var##_mem = malloc((size)*2 + 63); /* NOLINT */ \ - uint16_t* var = (uint16_t*)(((intptr_t)var##_mem + 63) & ~63) /* NOLINT */ - -#define free_aligned_buffer_64_16(var) \ - free(var##_mem); \ - var = NULL - #if defined(__APPLE__) || defined(__x86_64__) || defined(__llvm__) #define OMITFP #else diff --git a/include/libyuv/version.h b/include/libyuv/version.h index e78a4fee..569cb49b 100644 --- a/include/libyuv/version.h +++ b/include/libyuv/version.h @@ -11,6 +11,6 @@ #ifndef INCLUDE_LIBYUV_VERSION_H_ #define INCLUDE_LIBYUV_VERSION_H_ -#define LIBYUV_VERSION 1878 +#define LIBYUV_VERSION 1879 #endif // INCLUDE_LIBYUV_VERSION_H_ diff --git a/source/convert.cc b/source/convert.cc index b68fb1d3..0f48572d 100644 --- a/source/convert.cc +++ b/source/convert.cc @@ -776,6 +776,7 @@ int I422ToNV21(const uint8_t* src_y, // Allocate u and v buffers align_buffer_64(plane_u, halfwidth * halfheight * 2); + if (!plane_u) return 1; uint8_t* plane_v = plane_u + halfwidth * halfheight; I422ToI420(src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, @@ -892,6 +893,7 @@ int MT2TToP010(const uint8_t* src_y, void (*UnpackMT2T)(const uint8_t* src, uint16_t* dst, size_t size) = UnpackMT2T_C; align_buffer_64(row_buf, row_buf_size); + if (!row_buf) return 1; #if defined(HAS_UNPACKMT2T_NEON) if (TestCpuFlag(kCpuHasNEON)) { @@ -1091,6 +1093,7 @@ int I422ToNV21(const uint8_t* src_y, // Allocate 2 rows of vu. int awidth = halfwidth * 2; align_buffer_64(row_vu_0, awidth * 2); + if (!row_vu_0) return 1; uint8_t* row_vu_1 = row_vu_0 + awidth; for (y = 0; y < height - 1; y += 2) { @@ -2660,6 +2663,7 @@ int RGB24ToI420(const uint8_t* src_rgb24, // Allocate 2 rows of ARGB. const int row_size = (width * 4 + 31) & ~31; align_buffer_64(row, row_size * 2); + if (!row) return 1; #endif for (y = 0; y < height - 1; y += 2) { @@ -2836,6 +2840,7 @@ int RGB24ToJ420(const uint8_t* src_rgb24, // Allocate 2 rows of ARGB. const int row_size = (width * 4 + 31) & ~31; align_buffer_64(row, row_size * 2); + if (!row) return 1; #endif for (y = 0; y < height - 1; y += 2) { @@ -3015,6 +3020,7 @@ int RAWToI420(const uint8_t* src_raw, // Allocate 2 rows of ARGB. const int row_size = (width * 4 + 31) & ~31; align_buffer_64(row, row_size * 2); + if (!row) return 1; #endif for (y = 0; y < height - 1; y += 2) { @@ -3191,6 +3197,7 @@ int RAWToJ420(const uint8_t* src_raw, // Allocate 2 rows of ARGB. const int row_size = (width * 4 + 31) & ~31; align_buffer_64(row, row_size * 2); + if (!row) return 1; #endif for (y = 0; y < height - 1; y += 2) { @@ -3369,6 +3376,7 @@ int RGB565ToI420(const uint8_t* src_rgb565, // Allocate 2 rows of ARGB. const int row_size = (width * 4 + 31) & ~31; align_buffer_64(row, row_size * 2); + if (!row) return 1; #endif for (y = 0; y < height - 1; y += 2) { #if (defined(HAS_RGB565TOYROW_NEON) || defined(HAS_RGB565TOYROW_MSA) || \ @@ -3549,6 +3557,7 @@ int ARGB1555ToI420(const uint8_t* src_argb1555, // Allocate 2 rows of ARGB. const int row_size = (width * 4 + 31) & ~31; align_buffer_64(row, row_size * 2); + if (!row) return 1; #endif for (y = 0; y < height - 1; y += 2) { @@ -3762,6 +3771,7 @@ int ARGB4444ToI420(const uint8_t* src_argb4444, // Allocate 2 rows of ARGB. const int row_size = (width * 4 + 31) & ~31; align_buffer_64(row, row_size * 2); + if (!row) return 1; #endif for (y = 0; y < height - 1; y += 2) { diff --git a/source/convert_argb.cc b/source/convert_argb.cc index 5c946c3a..ad4470c7 100644 --- a/source/convert_argb.cc +++ b/source/convert_argb.cc @@ -4670,6 +4670,7 @@ int Android420ToARGBMatrix(const uint8_t* src_y, // General case fallback creates NV12 align_buffer_64(plane_uv, halfwidth * 2 * halfheight); + if (!plane_uv) return 1; dst_uv = plane_uv; for (y = 0; y < halfheight; ++y) { WeavePixels(src_u, src_v, src_pixel_stride_uv, dst_uv, halfwidth); @@ -5982,6 +5983,7 @@ int I420ToRGB565Dither(const uint8_t* src_y, { // Allocate a row of argb. align_buffer_64(row_argb, width * 4); + if (!row_argb) return 1; for (y = 0; y < height; ++y) { I422ToARGBRow(src_y, src_u, src_v, row_argb, &kYuvI601Constants, width); ARGBToRGB565DitherRow(row_argb, dst_rgb565, @@ -6240,6 +6242,7 @@ static int I420ToARGBMatrixBilinear(const uint8_t* src_y, // alloc 4 lines temp const int row_size = (width + 31) & ~31; align_buffer_64(row, row_size * 4); + if (!row) return 1; uint8_t* temp_u_1 = row; uint8_t* temp_u_2 = row + row_size; uint8_t* temp_v_1 = row + row_size * 2; @@ -6376,6 +6379,7 @@ static int I422ToARGBMatrixLinear(const uint8_t* src_y, // alloc 2 lines temp const int row_size = (width + 31) & ~31; align_buffer_64(row, row_size * 2); + if (!row) return 1; uint8_t* temp_u = row; uint8_t* temp_v = row + row_size; @@ -6507,6 +6511,7 @@ static int I420ToRGB24MatrixBilinear(const uint8_t* src_y, // alloc 4 lines temp const int row_size = (width + 31) & ~31; align_buffer_64(row, row_size * 4); + if (!row) return 1; uint8_t* temp_u_1 = row; uint8_t* temp_u_2 = row + row_size; uint8_t* temp_v_1 = row + row_size * 2; @@ -6613,6 +6618,7 @@ static int I010ToAR30MatrixBilinear(const uint16_t* src_y, // alloc 4 lines temp const int row_size = (width + 31) & ~31; align_buffer_64(row, row_size * 4 * sizeof(uint16_t)); + if (!row) return 1; uint16_t* temp_u_1 = (uint16_t*)(row); uint16_t* temp_u_2 = (uint16_t*)(row) + row_size; uint16_t* temp_v_1 = (uint16_t*)(row) + row_size * 2; @@ -6712,6 +6718,7 @@ static int I210ToAR30MatrixLinear(const uint16_t* src_y, // alloc 2 lines temp const int row_size = (width + 31) & ~31; align_buffer_64(row, row_size * 2 * sizeof(uint16_t)); + if (!row) return 1; uint16_t* temp_u = (uint16_t*)(row); uint16_t* temp_v = (uint16_t*)(row) + row_size; @@ -6800,6 +6807,7 @@ static int I010ToARGBMatrixBilinear(const uint16_t* src_y, // alloc 4 lines temp const int row_size = (width + 31) & ~31; align_buffer_64(row, row_size * 4 * sizeof(uint16_t)); + if (!row) return 1; uint16_t* temp_u_1 = (uint16_t*)(row); uint16_t* temp_u_2 = (uint16_t*)(row) + row_size; uint16_t* temp_v_1 = (uint16_t*)(row) + row_size * 2; @@ -6898,6 +6906,7 @@ static int I210ToARGBMatrixLinear(const uint16_t* src_y, // alloc 2 lines temp const int row_size = (width + 31) & ~31; align_buffer_64(row, row_size * 2 * sizeof(uint16_t)); + if (!row) return 1; uint16_t* temp_u = (uint16_t*)(row); uint16_t* temp_v = (uint16_t*)(row) + row_size; @@ -7074,6 +7083,7 @@ static int I420AlphaToARGBMatrixBilinear( // alloc 4 lines temp const int row_size = (width + 31) & ~31; align_buffer_64(row, row_size * 4); + if (!row) return 1; uint8_t* temp_u_1 = row; uint8_t* temp_u_2 = row + row_size; uint8_t* temp_v_1 = row + row_size * 2; @@ -7274,6 +7284,7 @@ static int I422AlphaToARGBMatrixLinear(const uint8_t* src_y, // alloc 2 lines temp const int row_size = (width + 31) & ~31; align_buffer_64(row, row_size * 2); + if (!row) return 1; uint8_t* temp_u = row; uint8_t* temp_v = row + row_size; @@ -7413,6 +7424,7 @@ static int I010AlphaToARGBMatrixBilinear( // alloc 4 lines temp const int row_size = (width + 31) & ~31; align_buffer_64(row, row_size * 4 * sizeof(uint16_t)); + if (!row) return 1; uint16_t* temp_u_1 = (uint16_t*)(row); uint16_t* temp_u_2 = (uint16_t*)(row) + row_size; uint16_t* temp_v_1 = (uint16_t*)(row) + row_size * 2; @@ -7574,6 +7586,7 @@ static int I210AlphaToARGBMatrixLinear(const uint16_t* src_y, // alloc 2 lines temp const int row_size = (width + 31) & ~31; align_buffer_64(row, row_size * 2 * sizeof(uint16_t)); + if (!row) return 1; uint16_t* temp_u = (uint16_t*)(row); uint16_t* temp_v = (uint16_t*)(row) + row_size; @@ -7659,6 +7672,7 @@ static int P010ToARGBMatrixBilinear(const uint16_t* src_y, // alloc 2 lines temp const int row_size = (2 * width + 31) & ~31; align_buffer_64(row, row_size * 2 * sizeof(uint16_t)); + if (!row) return 1; uint16_t* temp_uv_1 = (uint16_t*)(row); uint16_t* temp_uv_2 = (uint16_t*)(row) + row_size; @@ -7749,6 +7763,7 @@ static int P210ToARGBMatrixLinear(const uint16_t* src_y, const int row_size = (2 * width + 31) & ~31; align_buffer_64(row, row_size * sizeof(uint16_t)); + if (!row) return 1; uint16_t* temp_uv = (uint16_t*)(row); for (y = 0; y < height; ++y) { @@ -7827,6 +7842,7 @@ static int P010ToAR30MatrixBilinear(const uint16_t* src_y, // alloc 2 lines temp const int row_size = (2 * width + 31) & ~31; align_buffer_64(row, row_size * 2 * sizeof(uint16_t)); + if (!row) return 1; uint16_t* temp_uv_1 = (uint16_t*)(row); uint16_t* temp_uv_2 = (uint16_t*)(row) + row_size; @@ -7917,6 +7933,7 @@ static int P210ToAR30MatrixLinear(const uint16_t* src_y, const int row_size = (2 * width + 31) & ~31; align_buffer_64(row, row_size * sizeof(uint16_t)); + if (!row) return 1; uint16_t* temp_uv = (uint16_t*)(row); for (y = 0; y < height; ++y) { @@ -8017,6 +8034,7 @@ static int I422ToRGB24MatrixLinear(const uint8_t* src_y, // alloc 2 lines temp const int row_size = (width + 31) & ~31; align_buffer_64(row, row_size * 2); + if (!row) return 1; uint8_t* temp_u = row; uint8_t* temp_v = row + row_size; diff --git a/source/convert_from_argb.cc b/source/convert_from_argb.cc index 96129d84..1c0d250d 100644 --- a/source/convert_from_argb.cc +++ b/source/convert_from_argb.cc @@ -462,6 +462,7 @@ int ARGBToNV12(const uint8_t* src_argb, { // Allocate a rows of uv. align_buffer_64(row_u, ((halfwidth + 31) & ~31) * 2); + if (!row_u) return 1; uint8_t* row_v = row_u + ((halfwidth + 31) & ~31); for (y = 0; y < height - 1; y += 2) { @@ -660,6 +661,7 @@ int ARGBToNV21(const uint8_t* src_argb, { // Allocate a rows of uv. align_buffer_64(row_u, ((halfwidth + 31) & ~31) * 2); + if (!row_u) return 1; uint8_t* row_v = row_u + ((halfwidth + 31) & ~31); for (y = 0; y < height - 1; y += 2) { @@ -845,6 +847,7 @@ int ABGRToNV12(const uint8_t* src_abgr, { // Allocate a rows of uv. align_buffer_64(row_u, ((halfwidth + 31) & ~31) * 2); + if (!row_u) return 1; uint8_t* row_v = row_u + ((halfwidth + 31) & ~31); for (y = 0; y < height - 1; y += 2) { @@ -1031,6 +1034,7 @@ int ABGRToNV21(const uint8_t* src_abgr, { // Allocate a rows of uv. align_buffer_64(row_u, ((halfwidth + 31) & ~31) * 2); + if (!row_u) return 1; uint8_t* row_v = row_u + ((halfwidth + 31) & ~31); for (y = 0; y < height - 1; y += 2) { @@ -1230,6 +1234,7 @@ int ARGBToYUY2(const uint8_t* src_argb, { // Allocate a rows of yuv. align_buffer_64(row_y, ((width + 63) & ~63) * 2); + if (!row_y) return 1; uint8_t* row_u = row_y + ((width + 63) & ~63); uint8_t* row_v = row_u + ((width + 63) & ~63) / 2; @@ -1424,6 +1429,7 @@ int ARGBToUYVY(const uint8_t* src_argb, { // Allocate a rows of yuv. align_buffer_64(row_y, ((width + 63) & ~63) * 2); + if (!row_y) return 1; uint8_t* row_u = row_y + ((width + 63) & ~63); uint8_t* row_v = row_u + ((width + 63) & ~63) / 2; @@ -3274,11 +3280,13 @@ int RAWToJNV21(const uint8_t* src_raw, { // Allocate a row of uv. align_buffer_64(row_uj, ((halfwidth + 31) & ~31) * 2); + if (!row_uj) return 1; uint8_t* row_vj = row_uj + ((halfwidth + 31) & ~31); #if !defined(HAS_RAWTOYJROW) // Allocate 2 rows of ARGB. const int row_size = (width * 4 + 31) & ~31; align_buffer_64(row, row_size * 2); + if (!row) return 1; #endif for (y = 0; y < height - 1; y += 2) { diff --git a/source/planar_functions.cc b/source/planar_functions.cc index f6ec0dac..93a714e6 100644 --- a/source/planar_functions.cc +++ b/source/planar_functions.cc @@ -3027,6 +3027,7 @@ int I420Blend(const uint8_t* src_y0, // Row buffer for intermediate alpha pixels. align_buffer_64(halfalpha, halfwidth); + if (!halfalpha) return 1; for (y = 0; y < height; y += 2) { // last row of odd height image use 1 row of alpha instead of 2. if (y == (height - 1)) { @@ -4710,6 +4711,7 @@ int GaussPlane_F32(const float* src, { // 2 pixels on each side, but aligned out to 16 bytes. align_buffer_64(rowbuf, (4 + width + 4) * 4); + if (!rowbuf) return 1; memset(rowbuf, 0, 16); memset(rowbuf + (4 + width) * 4, 0, 16); float* row = (float*)(rowbuf + 16); @@ -4860,6 +4862,7 @@ static int ARGBSobelize(const uint8_t* src_argb, // 3 rows with edges before/after. const int row_size = (width + kEdge + 31) & ~31; align_buffer_64(rows, row_size * 2 + (kEdge + row_size * 3 + kEdge)); + if (!rows) return 1; uint8_t* row_sobelx = rows; uint8_t* row_sobely = rows + row_size; uint8_t* row_y = rows + row_size * 2; @@ -5654,6 +5657,7 @@ int UYVYToNV12(const uint8_t* src_uyvy, int awidth = halfwidth * 2; // row of y and 2 rows of uv align_buffer_64(rows, awidth * 3); + if (!rows) return 1; for (y = 0; y < height - 1; y += 2) { // Split Y from UV. diff --git a/source/rotate.cc b/source/rotate.cc index 3678b80a..0ee453c1 100644 --- a/source/rotate.cc +++ b/source/rotate.cc @@ -140,6 +140,7 @@ void RotatePlane180(const uint8_t* src, int height) { // Swap top and bottom row and mirror the content. Uses a temporary row. align_buffer_64(row, width); + if (!row) return; const uint8_t* src_bot = src + src_stride * (height - 1); uint8_t* dst_bot = dst + dst_stride * (height - 1); int half_height = (height + 1) >> 1; @@ -544,7 +545,9 @@ static void RotatePlane180_16(const uint16_t* src, int width, int height) { // Swap top and bottom row and mirror the content. Uses a temporary row. - align_buffer_64_16(row, width); + align_buffer_64(row, width * 2); + if (!row) return; + uint16_t* row_bot = (uint16_t*) row; const uint16_t* src_bot = src + src_stride * (height - 1); uint16_t* dst_bot = dst + dst_stride * (height - 1); int half_height = (height + 1) >> 1; @@ -552,15 +555,15 @@ static void RotatePlane180_16(const uint16_t* src, // Odd height will harmlessly mirror the middle row twice. for (y = 0; y < half_height; ++y) { - CopyRow_16_C(src, row, width); // Copy top row into buffer + CopyRow_16_C(src, row_bot, width); // Copy top row into buffer MirrorRow_16_C(src_bot, dst, width); // Mirror bottom row into top row - MirrorRow_16_C(row, dst_bot, width); // Mirror buffer into bottom row + MirrorRow_16_C(row_bot, dst_bot, width); // Mirror buffer into bottom row src += src_stride; dst += dst_stride; src_bot -= src_stride; dst_bot -= dst_stride; } - free_aligned_buffer_64_16(row); + free_aligned_buffer_64(row); } LIBYUV_API diff --git a/source/rotate_argb.cc b/source/rotate_argb.cc index 034d53e8..70a1ee98 100644 --- a/source/rotate_argb.cc +++ b/source/rotate_argb.cc @@ -121,6 +121,7 @@ static int ARGBRotate180(const uint8_t* src_argb, int height) { // Swap first and last row and mirror the content. Uses a temporary row. align_buffer_64(row, width * 4); + if (!row) return 1; const uint8_t* src_bot = src_argb + src_stride_argb * (height - 1); uint8_t* dst_bot = dst_argb + dst_stride_argb * (height - 1); int half_height = (height + 1) >> 1; diff --git a/source/scale.cc b/source/scale.cc index a8c70949..ac6a3bad 100644 --- a/source/scale.cc +++ b/source/scale.cc @@ -960,6 +960,7 @@ static void ScalePlaneBox(int src_width, { // Allocate a row buffer of uint16_t. align_buffer_64(row16, src_width * 2); + if (!row16) return; void (*ScaleAddCols)(int dst_width, int boxheight, int x, int dx, const uint16_t* src_ptr, uint8_t* dst_ptr) = (dx & 0xffff) ? ScaleAddCols2_C @@ -1054,6 +1055,7 @@ static void ScalePlaneBox_16(int src_width, { // Allocate a row buffer of uint32_t. align_buffer_64(row32, src_width * 4); + if (!row32) return; void (*ScaleAddCols)(int dst_width, int boxheight, int x, int dx, const uint32_t* src_ptr, uint16_t* dst_ptr) = (dx & 0xffff) ? ScaleAddCols2_16_C : ScaleAddCols1_16_C; @@ -1105,6 +1107,7 @@ static void ScalePlaneBilinearDown(int src_width, // TODO(fbarchard): Consider not allocating row buffer for kFilterLinear. // Allocate a row buffer. align_buffer_64(row, src_width); + if (!row) return; const int max_y = (src_height - 1) << 16; int j; @@ -1233,6 +1236,7 @@ static void ScalePlaneBilinearDown_16(int src_width, // TODO(fbarchard): Consider not allocating row buffer for kFilterLinear. // Allocate a row buffer. align_buffer_64(row, src_width * 2); + if (!row) return; const int max_y = (src_height - 1) << 16; int j; @@ -1415,6 +1419,7 @@ static void ScalePlaneBilinearUp(int src_width, // Allocate 2 row buffers. const int row_size = (dst_width + 31) & ~31; align_buffer_64(row, row_size * 2); + if (!row) return; uint8_t* rowptr = row; int rowstride = row_size; @@ -1882,6 +1887,7 @@ static void ScalePlaneBilinearUp_16(int src_width, // Allocate 2 row buffers. const int row_size = (dst_width + 31) & ~31; align_buffer_64(row, row_size * 4); + if (!row) return; uint16_t* rowptr = (uint16_t*)row; int rowstride = row_size; 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, diff --git a/source/scale_uv.cc b/source/scale_uv.cc index 536b9436..1c37be4f 100644 --- a/source/scale_uv.cc +++ b/source/scale_uv.cc @@ -204,6 +204,7 @@ static void ScaleUVDown4Box(int src_width, // Allocate 2 rows of UV. const int row_size = (dst_width * 2 * 2 + 15) & ~15; align_buffer_64(row, row_size * 2); + if (!row) return; int row_stride = src_stride * (dy >> 16); void (*ScaleUVRowDown2)(const uint8_t* src_uv, ptrdiff_t src_stride, uint8_t* dst_uv, int dst_width) = @@ -447,6 +448,7 @@ static void ScaleUVBilinearDown(int src_width, // Allocate a row of UV. { align_buffer_64(row, clip_src_width * 2); + if (!row) return; const int max_y = (src_height - 1) << 16; if (y > max_y) { @@ -606,6 +608,7 @@ static void ScaleUVBilinearUp(int src_width, // Allocate 2 rows of UV. const int row_size = (dst_width * 2 + 15) & ~15; align_buffer_64(row, row_size * 2); + if (!row) return; uint8_t* rowptr = row; int rowstride = row_size; |