diff --git a/source/convert.cc b/source/convert.cc index 9ad364e11..84198c137 100644 --- a/source/convert.cc +++ b/source/convert.cc @@ -100,16 +100,16 @@ int I420Copy(const uint8_t* src_y, int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; halfheight = (height + 1) >> 1; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (halfheight - 1) * src_stride_u; - src_v = src_v + (halfheight - 1) * src_stride_v; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(halfheight - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(halfheight - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; @@ -143,16 +143,16 @@ int I010Copy(const uint16_t* src_y, int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; halfheight = (height + 1) >> 1; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (halfheight - 1) * src_stride_u; - src_v = src_v + (halfheight - 1) * src_stride_v; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(halfheight - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(halfheight - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; @@ -188,16 +188,16 @@ static int Planar16bitTo8bit(const uint16_t* src_y, int uv_height = SUBSAMPLE(height, subsample_y, subsample_y); int scale = 1 << (24 - depth); if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; uv_height = -uv_height; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (uv_height - 1) * src_stride_u; - src_v = src_v + (uv_height - 1) * src_stride_v; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(uv_height - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(uv_height - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; @@ -233,15 +233,15 @@ static int I41xToI420(const uint16_t* src_y, int depth) { const int scale = 1 << (24 - depth); - if (width <= 0 || height == 0) { + if (width <= 0 || height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (height - 1) * src_stride_u; - src_v = src_v + (height - 1) * src_stride_v; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(height - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(height - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; @@ -278,15 +278,15 @@ static int I21xToI420(const uint16_t* src_y, int depth) { const int scale = 1 << (24 - depth); - if (width <= 0 || height == 0) { + if (width <= 0 || height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (height - 1) * src_stride_u; - src_v = src_v + (height - 1) * src_stride_v; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(height - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(height - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; @@ -541,7 +541,7 @@ static int Ix10ToI010(const uint16_t* src_y, const int dst_uv_height = SUBSAMPLE(dst_y_height, 1, 1); int r; if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } if (dst_y) { @@ -615,7 +615,7 @@ static int IxxxToPxxx(const uint16_t* src_y, int depth) { const int uv_width = SUBSAMPLE(width, subsample_x, subsample_x); const int uv_height = SUBSAMPLE(height, subsample_y, subsample_y); - if (width <= 0 || height == 0) { + if (width <= 0 || height == 0 || height == INT_MIN) { return -1; } @@ -666,16 +666,16 @@ int I010ToNV12(const uint16_t* src_y, void (*MergeUVRow)(const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_uv, int width) = MergeUVRow_C; if ((!src_y && dst_y) || !src_u || !src_v || !dst_uv || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; halfheight = (height + 1) >> 1; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (halfheight - 1) * src_stride_u; - src_v = src_v + (halfheight - 1) * src_stride_v; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(halfheight - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(halfheight - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; @@ -889,15 +889,15 @@ int I422ToI210(const uint8_t* src_y, int height) { int halfwidth = (width + 1) >> 1; if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (height - 1) * src_stride_u; - src_v = src_v + (height - 1) * src_stride_v; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(height - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(height - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; @@ -928,15 +928,19 @@ int I422ToNV21(const uint8_t* src_y, int dst_stride_vu, int width, int height) { + int r; + if (width <= 0 || height == 0 || height == INT_MIN) { + return -1; + } int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; // Negative height means invert the image. if (height < 0) { height = -height; halfheight = (height + 1) >> 1; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (height - 1) * src_stride_u; - src_v = src_v + (height - 1) * src_stride_v; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(height - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(height - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; @@ -951,9 +955,12 @@ int I422ToNV21(const uint8_t* src_y, return 1; uint8_t* plane_v = plane_u + (size_t)plane_size; - I422ToI420(src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, - dst_y, dst_stride_y, plane_u, halfwidth, plane_v, halfwidth, width, - height); + r = I422ToI420(src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v, + dst_y, dst_stride_y, plane_u, halfwidth, plane_v, halfwidth, + width, height); + if (r != 0) { + return r; + } MergeUVPlane(plane_v, halfwidth, plane_u, halfwidth, dst_vu, dst_stride_vu, halfwidth, halfheight); free_aligned_buffer_64(plane_u); @@ -1047,7 +1054,7 @@ int MT2TToP010(const uint8_t* src_y, int dst_stride_uv, int width, int height) { - if (width <= 0 || !height || !src_uv || !dst_uv) { + if (width <= 0 || height == 0 || height == INT_MIN || !src_uv || !dst_uv) { return -1; } @@ -1078,10 +1085,10 @@ int MT2TToP010(const uint8_t* src_y, height = -height; uv_height = (height + 1) / 2; if (dst_y) { - dst_y = dst_y + (height - 1) * dst_stride_y; + dst_y = dst_y + (ptrdiff_t)(height - 1) * dst_stride_y; dst_stride_y = -dst_stride_y; } - dst_uv = dst_uv + (uv_height - 1) * dst_stride_uv; + dst_uv = dst_uv + (ptrdiff_t)(uv_height - 1) * dst_stride_uv; dst_stride_uv = -dst_stride_uv; } @@ -1147,16 +1154,16 @@ int I422ToNV21(const uint8_t* src_y, int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; if ((!src_y && dst_y) || !src_u || !src_v || !dst_vu || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; halfheight = (height + 1) >> 1; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (halfheight - 1) * src_stride_u; - src_v = src_v + (halfheight - 1) * src_stride_v; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(halfheight - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(halfheight - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; @@ -1311,15 +1318,15 @@ int I444ToNV12(const uint8_t* src_y, int width, int height) { if ((!src_y && dst_y) || !src_u || !src_v || !dst_uv || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (height - 1) * src_stride_u; - src_v = src_v + (height - 1) * src_stride_v; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(height - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(height - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; @@ -1364,14 +1371,15 @@ int I400ToI420(const uint8_t* src_y, int height) { int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; - if ((!src_y && dst_y) || !dst_u || !dst_v || width <= 0 || height == 0) { + if ((!src_y && dst_y) || !dst_u || !dst_v || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; halfheight = (height + 1) >> 1; - src_y = src_y + (height - 1) * src_stride_y; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; src_stride_y = -src_stride_y; } if (dst_y) { @@ -1394,14 +1402,15 @@ int I400ToNV21(const uint8_t* src_y, int height) { int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; - if ((!src_y && dst_y) || !dst_vu || width <= 0 || height == 0) { + if ((!src_y && dst_y) || !dst_vu || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; halfheight = (height + 1) >> 1; - src_y = src_y + (height - 1) * src_stride_y; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; src_stride_y = -src_stride_y; } if (dst_y) { @@ -1429,15 +1438,15 @@ int NV12ToI420(const uint8_t* src_y, int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; if ((!src_y && dst_y) || !src_uv || !dst_u || !dst_v || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; halfheight = (height + 1) >> 1; - src_y = src_y + (height - 1) * src_stride_y; - src_uv = src_uv + (halfheight - 1) * src_stride_uv; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_uv = src_uv + (ptrdiff_t)(halfheight - 1) * src_stride_uv; src_stride_y = -src_stride_y; src_stride_uv = -src_stride_uv; } @@ -1499,7 +1508,8 @@ int NV12ToNV24(const uint8_t* src_y, int width, int height) { int r; - if ((!src_y && dst_y) || !src_uv || !dst_uv || width <= 0 || height == 0) { + if ((!src_y && dst_y) || !src_uv || !dst_uv || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } @@ -1524,7 +1534,8 @@ int NV16ToNV24(const uint8_t* src_y, int width, int height) { int r; - if ((!src_y && dst_y) || !src_uv || !dst_uv || width <= 0 || height == 0) { + if ((!src_y && dst_y) || !src_uv || !dst_uv || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } @@ -1555,7 +1566,7 @@ static int PxxxToIxxx(const uint16_t* src_y, const int uv_width = SUBSAMPLE(width, subsample_x, subsample_x); const int uv_height = SUBSAMPLE(height, subsample_y, subsample_y); if (!src_y || !dst_y || !src_uv || !dst_u || !dst_v || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } ConvertToLSBPlane_16(src_y, src_stride_y, dst_y, dst_stride_y, width, height, @@ -1613,7 +1624,8 @@ int P010ToP410(const uint16_t* src_y, int width, int height) { int r; - if ((!src_y && dst_y) || !src_uv || !dst_uv || width <= 0 || height == 0) { + if ((!src_y && dst_y) || !src_uv || !dst_uv || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } @@ -1638,7 +1650,8 @@ int P210ToP410(const uint16_t* src_y, int width, int height) { int r; - if ((!src_y && dst_y) || !src_uv || !dst_uv || width <= 0 || height == 0) { + if ((!src_y && dst_y) || !src_uv || !dst_uv || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } @@ -1668,10 +1681,13 @@ int YUY2ToI420(const uint8_t* src_yuy2, YUY2ToUVRow_C; void (*YUY2ToYRow)(const uint8_t* src_yuy2, uint8_t* dst_y, int width) = YUY2ToYRow_C; + if (width <= 0 || height == 0 || height == INT_MIN) { + return -1; + } // Negative height means invert the image. if (height < 0) { height = -height; - src_yuy2 = src_yuy2 + (height - 1) * src_stride_yuy2; + src_yuy2 = src_yuy2 + (ptrdiff_t)(height - 1) * src_stride_yuy2; src_stride_yuy2 = -src_stride_yuy2; } #if defined(HAS_YUY2TOYROW_SSE2) @@ -1759,10 +1775,13 @@ int UYVYToI420(const uint8_t* src_uyvy, UYVYToUVRow_C; void (*UYVYToYRow)(const uint8_t* src_uyvy, uint8_t* dst_y, int width) = UYVYToYRow_C; + if (width <= 0 || height == 0 || height == INT_MIN) { + return -1; + } // Negative height means invert the image. if (height < 0) { height = -height; - src_uyvy = src_uyvy + (height - 1) * src_stride_uyvy; + src_uyvy = src_uyvy + (ptrdiff_t)(height - 1) * src_stride_uyvy; src_stride_uyvy = -src_stride_uyvy; } #if defined(HAS_UYVYTOYROW_SSE2) @@ -1857,10 +1876,13 @@ int AYUVToNV12(const uint8_t* src_ayuv, uint8_t* dst_uv, int width) = AYUVToUVRow_C; void (*AYUVToYRow)(const uint8_t* src_ayuv, uint8_t* dst_y, int width) = AYUVToYRow_C; + if (width <= 0 || height == 0 || height == INT_MIN) { + return -1; + } // Negative height means invert the image. if (height < 0) { height = -height; - src_ayuv = src_ayuv + (height - 1) * src_stride_ayuv; + src_ayuv = src_ayuv + (ptrdiff_t)(height - 1) * src_stride_ayuv; src_stride_ayuv = -src_stride_ayuv; } // place holders for future intel code @@ -1934,10 +1956,13 @@ int AYUVToNV21(const uint8_t* src_ayuv, uint8_t* dst_vu, int width) = AYUVToVURow_C; void (*AYUVToYRow)(const uint8_t* src_ayuv, uint8_t* dst_y, int width) = AYUVToYRow_C; + if (width <= 0 || height == 0 || height == INT_MIN) { + return -1; + } // Negative height means invert the image. if (height < 0) { height = -height; - src_ayuv = src_ayuv + (height - 1) * src_stride_ayuv; + src_ayuv = src_ayuv + (ptrdiff_t)(height - 1) * src_stride_ayuv; src_stride_ayuv = -src_stride_ayuv; } // place holders for future intel code @@ -2150,13 +2175,13 @@ ARGBToUVMatrixRow_C; } #endif if (!src_argb || !dst_y || !dst_u || !dst_v || !argbconstants || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } @@ -2226,13 +2251,13 @@ int ARGBToI420Alpha(const uint8_t* src_argb, void (*ARGBExtractAlphaRow)(const uint8_t* src_argb, uint8_t* dst_a, int width) = ARGBExtractAlphaRow_C; if (!src_argb || !dst_y || !dst_u || !dst_v || !dst_a || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } #if defined(HAS_ARGBTOYROW_NEON) @@ -2566,13 +2591,14 @@ int RGB24ToI420(const uint8_t* src_rgb24, } #endif - if (!src_rgb24 || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0) { + if (!src_rgb24 || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_rgb24 = src_rgb24 + (height - 1) * src_stride_rgb24; + src_rgb24 = src_rgb24 + (ptrdiff_t)(height - 1) * src_stride_rgb24; src_stride_rgb24 = -src_stride_rgb24; } @@ -2626,13 +2652,14 @@ int RGB24ToJ420(const uint8_t* src_rgb24, void (*ARGBToYJRow)(const uint8_t* src_argb, uint8_t* dst_y, int width) = ARGBToYJRow_C; #endif - if (!src_rgb24 || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0) { + if (!src_rgb24 || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_rgb24 = src_rgb24 + (height - 1) * src_stride_rgb24; + src_rgb24 = src_rgb24 + (ptrdiff_t)(height - 1) * src_stride_rgb24; src_stride_rgb24 = -src_stride_rgb24; } @@ -2881,13 +2908,14 @@ int RAWToI420(const uint8_t* src_rgb24, } #endif - if (!src_rgb24 || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0) { + if (!src_rgb24 || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_rgb24 = src_rgb24 + (height - 1) * src_stride_rgb24; + src_rgb24 = src_rgb24 + (ptrdiff_t)(height - 1) * src_stride_rgb24; src_stride_rgb24 = -src_stride_rgb24; } @@ -2941,13 +2969,14 @@ int RAWToJ420(const uint8_t* src_raw, void (*ARGBToYJRow)(const uint8_t* src_argb, uint8_t* dst_y, int width) = ARGBToYJRow_C; #endif - if (!src_raw || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0) { + if (!src_raw || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_raw = src_raw + (height - 1) * src_stride_raw; + src_raw = src_raw + (ptrdiff_t)(height - 1) * src_stride_raw; src_stride_raw = -src_stride_raw; } @@ -3149,12 +3178,13 @@ int RAWToI444(const uint8_t* src_raw, ARGBToYRow_C; void (*ARGBToUV444Row)(const uint8_t* src_raw, uint8_t* dst_u, uint8_t* dst_v, int width) = ARGBToUV444Row_C; - if (!src_raw || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0) { + if (!src_raw || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } if (height < 0) { height = -height; - src_raw = src_raw + (height - 1) * src_stride_raw; + src_raw = src_raw + (ptrdiff_t)(height - 1) * src_stride_raw; src_stride_raw = -src_stride_raw; } // TODO: add row coalesce when main loop handles large width in blocks @@ -3377,12 +3407,13 @@ int RAWToJ444(const uint8_t* src_raw, ARGBToYJRow_C; void (*ARGBToUVJ444Row)(const uint8_t* src_raw, uint8_t* dst_u, uint8_t* dst_v, int width) = ARGBToUVJ444Row_C; - if (!src_raw || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0) { + if (!src_raw || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } if (height < 0) { height = -height; - src_raw = src_raw + (height - 1) * src_stride_raw; + src_raw = src_raw + (ptrdiff_t)(height - 1) * src_stride_raw; src_stride_raw = -src_stride_raw; } // TODO: add row coalesce when main loop handles large width in blocks @@ -3628,13 +3659,14 @@ int RGB565ToI420(const uint8_t* src_rgb565, } #endif - if (!src_rgb565 || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0) { + if (!src_rgb565 || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_rgb565 = src_rgb565 + (height - 1) * src_stride_rgb565; + src_rgb565 = src_rgb565 + (ptrdiff_t)(height - 1) * src_stride_rgb565; src_stride_rgb565 = -src_stride_rgb565; } @@ -3707,13 +3739,14 @@ int ARGB1555ToI420(const uint8_t* src_argb1555, } #endif - if (!src_argb1555 || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0) { + if (!src_argb1555 || !dst_y || !dst_u || !dst_v || width <= 0 || + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb1555 = src_argb1555 + (height - 1) * src_stride_argb1555; + src_argb1555 = src_argb1555 + (ptrdiff_t)(height - 1) * src_stride_argb1555; src_stride_argb1555 = -src_stride_argb1555; } @@ -3786,13 +3819,14 @@ int ARGB4444ToI420(const uint8_t* src_argb4444, } #endif - if (!src_argb4444 || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0) { + if (!src_argb4444 || !dst_y || !dst_u || !dst_v || width <= 0 || + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb4444 = src_argb4444 + (height - 1) * src_stride_argb4444; + src_argb4444 = src_argb4444 + (ptrdiff_t)(height - 1) * src_stride_argb4444; src_stride_argb4444 = -src_stride_argb4444; } @@ -3886,12 +3920,12 @@ int RGB24ToJ400(const uint8_t* src_rgb24, } #endif - if (!src_rgb24 || !dst_yj || width <= 0 || height == 0) { + if (!src_rgb24 || !dst_yj || width <= 0 || height == 0 || height == INT_MIN) { return -1; } if (height < 0) { height = -height; - src_rgb24 = src_rgb24 + (height - 1) * src_stride_rgb24; + src_rgb24 = src_rgb24 + (ptrdiff_t)(height - 1) * src_stride_rgb24; src_stride_rgb24 = -src_stride_rgb24; } // Coalesce rows. @@ -4052,12 +4086,12 @@ int RAWToJ400(const uint8_t* src_raw, } #endif - if (!src_raw || !dst_yj || width <= 0 || height == 0) { + if (!src_raw || !dst_yj || width <= 0 || height == 0 || height == INT_MIN) { return -1; } if (height < 0) { height = -height; - src_raw = src_raw + (height - 1) * src_stride_raw; + src_raw = src_raw + (ptrdiff_t)(height - 1) * src_stride_raw; src_stride_raw = -src_stride_raw; } // Coalesce rows. @@ -4185,15 +4219,16 @@ static int Biplanar16bitTo8bit(const uint16_t* src_y, int uv_width = SUBSAMPLE(width, subsample_x, subsample_x); int uv_height = SUBSAMPLE(height, subsample_y, subsample_y); int scale = 1 << (24 - depth); - if ((!src_y && dst_y) || !src_uv || !dst_uv || width <= 0 || height == 0) { + if ((!src_y && dst_y) || !src_uv || !dst_uv || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; uv_height = -uv_height; - src_y = src_y + (height - 1) * src_stride_y; - src_uv = src_uv + (uv_height - 1) * src_stride_uv; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_uv = src_uv + (ptrdiff_t)(uv_height - 1) * src_stride_uv; src_stride_y = -src_stride_y; src_stride_uv = -src_stride_uv; } @@ -4251,16 +4286,16 @@ static int Planar8bitTo8bit(const uint8_t* src_y, int uv_width = SUBSAMPLE(width, subsample_x, subsample_x); int uv_height = SUBSAMPLE(height, subsample_y, subsample_y); if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; uv_height = -uv_height; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (uv_height - 1) * src_stride_u; - src_v = src_v + (uv_height - 1) * src_stride_v; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(uv_height - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(uv_height - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; diff --git a/source/convert_argb.cc b/source/convert_argb.cc index 4f5059ac2..2df97d079 100644 --- a/source/convert_argb.cc +++ b/source/convert_argb.cc @@ -34,13 +34,14 @@ int ARGBCopy(const uint8_t* src_argb, int dst_stride_argb, int width, int height) { - if (!src_argb || !dst_argb || width <= 0 || height == 0) { + if (!src_argb || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } @@ -68,13 +69,14 @@ int I420ToARGBMatrix(const uint8_t* src_y, const struct YuvConstants* yuvconstants, int width) = I422ToARGBRow_C; assert(yuvconstants); - if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } #if defined(HAS_I422TOARGBROW_SSSE3) @@ -317,13 +319,14 @@ int I422ToARGBMatrix(const uint8_t* src_y, const struct YuvConstants* yuvconstants, int width) = I422ToARGBRow_C; assert(yuvconstants); - if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } // Coalesce rows. @@ -572,13 +575,14 @@ int I444ToARGBMatrix(const uint8_t* src_y, const struct YuvConstants* yuvconstants, int width) = I444ToARGBRow_C; assert(yuvconstants); - if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } // Coalesce rows. @@ -809,13 +813,14 @@ int I444ToRGB24Matrix(const uint8_t* src_y, const struct YuvConstants* yuvconstants, int width) = I444ToRGB24Row_C; assert(yuvconstants); - if (!src_y || !src_u || !src_v || !dst_rgb24 || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_rgb24 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_rgb24 = dst_rgb24 + (height - 1) * dst_stride_rgb24; + dst_rgb24 = dst_rgb24 + (ptrdiff_t)(height - 1) * dst_stride_rgb24; dst_stride_rgb24 = -dst_stride_rgb24; } // Coalesce rows. @@ -940,13 +945,14 @@ int I010ToAR30Matrix(const uint16_t* src_y, const struct YuvConstants* yuvconstants, int width) = I210ToAR30Row_C; assert(yuvconstants); - if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_ar30 = dst_ar30 + (height - 1) * dst_stride_ar30; + dst_ar30 = dst_ar30 + (ptrdiff_t)(height - 1) * dst_stride_ar30; dst_stride_ar30 = -dst_stride_ar30; } #if defined(HAS_I210TOAR30ROW_NEON) @@ -1118,13 +1124,14 @@ int I012ToAR30Matrix(const uint16_t* src_y, const struct YuvConstants* yuvconstants, int width) = I212ToAR30Row_C; assert(yuvconstants); - if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_ar30 = dst_ar30 + (height - 1) * dst_stride_ar30; + dst_ar30 = dst_ar30 + (ptrdiff_t)(height - 1) * dst_stride_ar30; dst_stride_ar30 = -dst_stride_ar30; } #if defined(HAS_I212TOAR30ROW_SSSE3) @@ -1194,13 +1201,14 @@ int I210ToAR30Matrix(const uint16_t* src_y, const struct YuvConstants* yuvconstants, int width) = I210ToAR30Row_C; assert(yuvconstants); - if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_ar30 = dst_ar30 + (height - 1) * dst_stride_ar30; + dst_ar30 = dst_ar30 + (ptrdiff_t)(height - 1) * dst_stride_ar30; dst_stride_ar30 = -dst_stride_ar30; } #if defined(HAS_I210TOAR30ROW_NEON) @@ -1367,13 +1375,14 @@ int I410ToAR30Matrix(const uint16_t* src_y, const struct YuvConstants* yuvconstants, int width) = I410ToAR30Row_C; assert(yuvconstants); - if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_ar30 = dst_ar30 + (height - 1) * dst_stride_ar30; + dst_ar30 = dst_ar30 + (ptrdiff_t)(height - 1) * dst_stride_ar30; dst_stride_ar30 = -dst_stride_ar30; } #if defined(HAS_I410TOAR30ROW_NEON) @@ -1439,13 +1448,14 @@ int I010ToARGBMatrix(const uint16_t* src_y, const struct YuvConstants* yuvconstants, int width) = I210ToARGBRow_C; assert(yuvconstants); - if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } #if defined(HAS_I210TOARGBROW_SSSE3) @@ -1621,13 +1631,14 @@ int I012ToARGBMatrix(const uint16_t* src_y, const struct YuvConstants* yuvconstants, int width) = I212ToARGBRow_C; assert(yuvconstants); - if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } #if defined(HAS_I212TOARGBROW_SSSE3) @@ -1695,13 +1706,14 @@ int I210ToARGBMatrix(const uint16_t* src_y, const struct YuvConstants* yuvconstants, int width) = I210ToARGBRow_C; assert(yuvconstants); - if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } #if defined(HAS_I210TOARGBROW_SSSE3) @@ -1874,13 +1886,14 @@ int I410ToARGBMatrix(const uint16_t* src_y, const struct YuvConstants* yuvconstants, int width) = I410ToARGBRow_C; assert(yuvconstants); - if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } #if defined(HAS_I410TOARGBROW_SSSE3) @@ -1942,13 +1955,14 @@ int P010ToARGBMatrix(const uint16_t* src_y, const uint16_t* y_buf, const uint16_t* uv_buf, uint8_t* rgb_buf, const struct YuvConstants* yuvconstants, int width) = P210ToARGBRow_C; assert(yuvconstants); - if (!src_y || !src_uv || !dst_argb || width <= 0 || height == 0) { + if (!src_y || !src_uv || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } #if defined(HAS_P210TOARGBROW_SSSE3) @@ -2011,13 +2025,14 @@ int P210ToARGBMatrix(const uint16_t* src_y, const uint16_t* y_buf, const uint16_t* uv_buf, uint8_t* rgb_buf, const struct YuvConstants* yuvconstants, int width) = P210ToARGBRow_C; assert(yuvconstants); - if (!src_y || !src_uv || !dst_argb || width <= 0 || height == 0) { + if (!src_y || !src_uv || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } #if defined(HAS_P210TOARGBROW_SSSE3) @@ -2078,13 +2093,14 @@ int P010ToAR30Matrix(const uint16_t* src_y, const uint16_t* y_buf, const uint16_t* uv_buf, uint8_t* rgb_buf, const struct YuvConstants* yuvconstants, int width) = P210ToAR30Row_C; assert(yuvconstants); - if (!src_y || !src_uv || !dst_ar30 || width <= 0 || height == 0) { + if (!src_y || !src_uv || !dst_ar30 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_ar30 = dst_ar30 + (height - 1) * dst_stride_ar30; + dst_ar30 = dst_ar30 + (ptrdiff_t)(height - 1) * dst_stride_ar30; dst_stride_ar30 = -dst_stride_ar30; } #if defined(HAS_P210TOAR30ROW_SSSE3) @@ -2147,13 +2163,14 @@ int P210ToAR30Matrix(const uint16_t* src_y, const uint16_t* y_buf, const uint16_t* uv_buf, uint8_t* rgb_buf, const struct YuvConstants* yuvconstants, int width) = P210ToAR30Row_C; assert(yuvconstants); - if (!src_y || !src_uv || !dst_ar30 || width <= 0 || height == 0) { + if (!src_y || !src_uv || !dst_ar30 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_ar30 = dst_ar30 + (height - 1) * dst_stride_ar30; + dst_ar30 = dst_ar30 + (ptrdiff_t)(height - 1) * dst_stride_ar30; dst_stride_ar30 = -dst_stride_ar30; } #if defined(HAS_P210TOAR30ROW_SSSE3) @@ -2225,13 +2242,13 @@ int I420AlphaToARGBMatrix(const uint8_t* src_y, int width) = ARGBAttenuateRow_C; assert(yuvconstants); if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } #if defined(HAS_I422ALPHATOARGBROW_SSSE3) @@ -2378,13 +2395,13 @@ int I422AlphaToARGBMatrix(const uint8_t* src_y, int width) = ARGBAttenuateRow_C; assert(yuvconstants); if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } #if defined(HAS_I422ALPHATOARGBROW_SSSE3) @@ -2529,13 +2546,13 @@ int I444AlphaToARGBMatrix(const uint8_t* src_y, int width) = ARGBAttenuateRow_C; assert(yuvconstants); if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } #if defined(HAS_I444ALPHATOARGBROW_SSSE3) @@ -2793,13 +2810,13 @@ int I010AlphaToARGBMatrix(const uint16_t* src_y, int width) = ARGBAttenuateRow_C; assert(yuvconstants); if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } #if defined(HAS_I210ALPHATOARGBROW_NEON) @@ -2925,13 +2942,13 @@ int I210AlphaToARGBMatrix(const uint16_t* src_y, int width) = ARGBAttenuateRow_C; assert(yuvconstants); if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } #if defined(HAS_I210ALPHATOARGBROW_NEON) @@ -3055,13 +3072,13 @@ int I410AlphaToARGBMatrix(const uint16_t* src_y, int width) = ARGBAttenuateRow_C; assert(yuvconstants); if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } #if defined(HAS_I410ALPHATOARGBROW_NEON) @@ -3173,13 +3190,13 @@ int I400ToARGBMatrix(const uint8_t* src_y, const struct YuvConstants* yuvconstants, int width) = I400ToARGBRow_C; assert(yuvconstants); - if (!src_y || !dst_argb || width <= 0 || height == 0) { + if (!src_y || !dst_argb || width <= 0 || height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } // Coalesce rows. @@ -3268,13 +3285,13 @@ int J400ToARGB(const uint8_t* src_y, int y; void (*J400ToARGBRow)(const uint8_t* src_y, uint8_t* dst_argb, int width) = J400ToARGBRow_C; - if (!src_y || !dst_argb || width <= 0 || height == 0) { + if (!src_y || !dst_argb || width <= 0 || height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_y = src_y + (height - 1) * src_stride_y; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; src_stride_y = -src_stride_y; } // Coalesce rows. @@ -3443,13 +3460,14 @@ int ARGBToBGRA(const uint8_t* src_argb, int y; void (*ARGBToBGRARow)(const uint8_t* src_argb, uint8_t* dst_bgra, int width) = ARGBToBGRARow_C; - if (!src_argb || !dst_bgra || width <= 0 || height == 0) { + if (!src_argb || !dst_bgra || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. @@ -3485,13 +3503,14 @@ int ARGBToABGR(const uint8_t* src_argb, int y; void (*ARGBToABGRRow)(const uint8_t* src_argb, uint8_t* dst_abgr, int width) = ARGBToABGRRow_C; - if (!src_argb || !dst_abgr || width <= 0 || height == 0) { + if (!src_argb || !dst_abgr || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. @@ -3539,13 +3558,14 @@ int RGBAToARGB(const uint8_t* src_rgba, int y; void (*RGBAToARGBRow)(const uint8_t* src_rgba, uint8_t* dst_argb, int width) = RGBAToARGBRow_C; - if (!src_rgba || !dst_argb || width <= 0 || height == 0) { + if (!src_rgba || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_rgba = src_rgba + (height - 1) * src_stride_rgba; + src_rgba = src_rgba + (ptrdiff_t)(height - 1) * src_stride_rgba; src_stride_rgba = -src_stride_rgba; } // Coalesce rows. @@ -3581,13 +3601,14 @@ int AR64ToAB64(const uint16_t* src_ar64, int y; void (*AR64ToAB64Row)(const uint16_t* src_ar64, uint16_t* dst_ab64, int width) = AR64ToAB64Row_C; - if (!src_ar64 || !dst_ab64 || width <= 0 || height == 0) { + if (!src_ar64 || !dst_ab64 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_ar64 = src_ar64 + (height - 1) * src_stride_ar64; + src_ar64 = src_ar64 + (ptrdiff_t)(height - 1) * src_stride_ar64; src_stride_ar64 = -src_stride_ar64; } // Coalesce rows. @@ -3624,13 +3645,14 @@ int RGB24ToARGB(const uint8_t* src_rgb24, int y; void (*RGB24ToARGBRow)(const uint8_t* src_rgb, uint8_t* dst_argb, int width) = RGB24ToARGBRow_C; - if (!src_rgb24 || !dst_argb || width <= 0 || height == 0) { + if (!src_rgb24 || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_rgb24 = src_rgb24 + (height - 1) * src_stride_rgb24; + src_rgb24 = src_rgb24 + (ptrdiff_t)(height - 1) * src_stride_rgb24; src_stride_rgb24 = -src_stride_rgb24; } // Coalesce rows. @@ -3717,13 +3739,13 @@ int RAWToARGB(const uint8_t* src_raw, int y; void (*RAWToARGBRow)(const uint8_t* src_rgb, uint8_t* dst_argb, int width) = RAWToARGBRow_C; - if (!src_raw || !dst_argb || width <= 0 || height == 0) { + if (!src_raw || !dst_argb || width <= 0 || height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_raw = src_raw + (height - 1) * src_stride_raw; + src_raw = src_raw + (ptrdiff_t)(height - 1) * src_stride_raw; src_stride_raw = -src_stride_raw; } // Coalesce rows. @@ -3811,13 +3833,13 @@ int RAWToRGBA(const uint8_t* src_raw, int y; void (*RAWToRGBARow)(const uint8_t* src_rgb, uint8_t* dst_rgba, int width) = RAWToRGBARow_C; - if (!src_raw || !dst_rgba || width <= 0 || height == 0) { + if (!src_raw || !dst_rgba || width <= 0 || height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_raw = src_raw + (height - 1) * src_stride_raw; + src_raw = src_raw + (ptrdiff_t)(height - 1) * src_stride_raw; src_stride_raw = -src_stride_raw; } // Coalesce rows. @@ -3873,13 +3895,14 @@ int RGB565ToARGB(const uint8_t* src_rgb565, int y; void (*RGB565ToARGBRow)(const uint8_t* src_rgb565, uint8_t* dst_argb, int width) = RGB565ToARGBRow_C; - if (!src_rgb565 || !dst_argb || width <= 0 || height == 0) { + if (!src_rgb565 || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_rgb565 = src_rgb565 + (height - 1) * src_stride_rgb565; + src_rgb565 = src_rgb565 + (ptrdiff_t)(height - 1) * src_stride_rgb565; src_stride_rgb565 = -src_stride_rgb565; } // Coalesce rows. @@ -3942,13 +3965,14 @@ int ARGB1555ToARGB(const uint8_t* src_argb1555, int y; void (*ARGB1555ToARGBRow)(const uint8_t* src_argb1555, uint8_t* dst_argb, int width) = ARGB1555ToARGBRow_C; - if (!src_argb1555 || !dst_argb || width <= 0 || height == 0) { + if (!src_argb1555 || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb1555 = src_argb1555 + (height - 1) * src_stride_argb1555; + src_argb1555 = src_argb1555 + (ptrdiff_t)(height - 1) * src_stride_argb1555; src_stride_argb1555 = -src_stride_argb1555; } // Coalesce rows. @@ -4016,13 +4040,14 @@ int ARGB4444ToARGB(const uint8_t* src_argb4444, int y; void (*ARGB4444ToARGBRow)(const uint8_t* src_argb4444, uint8_t* dst_argb, int width) = ARGB4444ToARGBRow_C; - if (!src_argb4444 || !dst_argb || width <= 0 || height == 0) { + if (!src_argb4444 || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb4444 = src_argb4444 + (height - 1) * src_stride_argb4444; + src_argb4444 = src_argb4444 + (ptrdiff_t)(height - 1) * src_stride_argb4444; src_stride_argb4444 = -src_stride_argb4444; } // Coalesce rows. @@ -4083,13 +4108,14 @@ int AR30ToARGB(const uint8_t* src_ar30, int width, int height) { int y; - if (!src_ar30 || !dst_argb || width <= 0 || height == 0) { + if (!src_ar30 || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_ar30 = src_ar30 + (height - 1) * src_stride_ar30; + src_ar30 = src_ar30 + (ptrdiff_t)(height - 1) * src_stride_ar30; src_stride_ar30 = -src_stride_ar30; } // Coalesce rows. @@ -4116,13 +4142,14 @@ int AR30ToABGR(const uint8_t* src_ar30, int width, int height) { int y; - if (!src_ar30 || !dst_abgr || width <= 0 || height == 0) { + if (!src_ar30 || !dst_abgr || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_ar30 = src_ar30 + (height - 1) * src_stride_ar30; + src_ar30 = src_ar30 + (ptrdiff_t)(height - 1) * src_stride_ar30; src_stride_ar30 = -src_stride_ar30; } // Coalesce rows. @@ -4149,13 +4176,14 @@ int AR30ToAB30(const uint8_t* src_ar30, int width, int height) { int y; - if (!src_ar30 || !dst_ab30 || width <= 0 || height == 0) { + if (!src_ar30 || !dst_ab30 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_ar30 = src_ar30 + (height - 1) * src_stride_ar30; + src_ar30 = src_ar30 + (ptrdiff_t)(height - 1) * src_stride_ar30; src_stride_ar30 = -src_stride_ar30; } // Coalesce rows. @@ -4184,13 +4212,14 @@ int AR64ToARGB(const uint16_t* src_ar64, int y; void (*AR64ToARGBRow)(const uint16_t* src_ar64, uint8_t* dst_argb, int width) = AR64ToARGBRow_C; - if (!src_ar64 || !dst_argb || width <= 0 || height == 0) { + if (!src_ar64 || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_ar64 = src_ar64 + (height - 1) * src_stride_ar64; + src_ar64 = src_ar64 + (ptrdiff_t)(height - 1) * src_stride_ar64; src_stride_ar64 = -src_stride_ar64; } // Coalesce rows. @@ -4249,13 +4278,14 @@ int AB64ToARGB(const uint16_t* src_ab64, int y; void (*AB64ToARGBRow)(const uint16_t* src_ar64, uint8_t* dst_argb, int width) = AB64ToARGBRow_C; - if (!src_ab64 || !dst_argb || width <= 0 || height == 0) { + if (!src_ab64 || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_ab64 = src_ab64 + (height - 1) * src_stride_ab64; + src_ab64 = src_ab64 + (ptrdiff_t)(height - 1) * src_stride_ab64; src_stride_ab64 = -src_stride_ab64; } // Coalesce rows. @@ -4319,13 +4349,14 @@ int NV12ToARGBMatrix(const uint8_t* src_y, const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* rgb_buf, const struct YuvConstants* yuvconstants, int width) = NV12ToARGBRow_C; assert(yuvconstants); - if (!src_y || !src_uv || !dst_argb || width <= 0 || height == 0) { + if (!src_y || !src_uv || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } #if defined(HAS_NV12TOARGBROW_SSSE3) @@ -4411,13 +4442,14 @@ int NV21ToARGBMatrix(const uint8_t* src_y, const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* rgb_buf, const struct YuvConstants* yuvconstants, int width) = NV21ToARGBRow_C; assert(yuvconstants); - if (!src_y || !src_vu || !dst_argb || width <= 0 || height == 0) { + if (!src_y || !src_vu || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } #if defined(HAS_NV21TOARGBROW_SSSE3) @@ -4562,13 +4594,14 @@ int NV12ToRGB24Matrix(const uint8_t* src_y, const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* rgb_buf, const struct YuvConstants* yuvconstants, int width) = NV12ToRGB24Row_C; assert(yuvconstants); - if (!src_y || !src_uv || !dst_rgb24 || width <= 0 || height == 0) { + if (!src_y || !src_uv || !dst_rgb24 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_rgb24 = dst_rgb24 + (height - 1) * dst_stride_rgb24; + dst_rgb24 = dst_rgb24 + (ptrdiff_t)(height - 1) * dst_stride_rgb24; dst_stride_rgb24 = -dst_stride_rgb24; } #if defined(HAS_NV12TORGB24ROW_NEON) @@ -4638,13 +4671,14 @@ int NV21ToRGB24Matrix(const uint8_t* src_y, const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* rgb_buf, const struct YuvConstants* yuvconstants, int width) = NV21ToRGB24Row_C; assert(yuvconstants); - if (!src_y || !src_vu || !dst_rgb24 || width <= 0 || height == 0) { + if (!src_y || !src_vu || !dst_rgb24 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_rgb24 = dst_rgb24 + (height - 1) * dst_stride_rgb24; + dst_rgb24 = dst_rgb24 + (ptrdiff_t)(height - 1) * dst_stride_rgb24; dst_stride_rgb24 = -dst_stride_rgb24; } #if defined(HAS_NV21TORGB24ROW_NEON) @@ -4768,13 +4802,14 @@ int NV21ToYUV24(const uint8_t* src_y, int y; void (*NV21ToYUV24Row)(const uint8_t* src_y, const uint8_t* src_vu, uint8_t* dst_yuv24, int width) = NV21ToYUV24Row_C; - if (!src_y || !src_vu || !dst_yuv24 || width <= 0 || height == 0) { + if (!src_y || !src_vu || !dst_yuv24 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_yuv24 = dst_yuv24 + (height - 1) * dst_stride_yuv24; + dst_yuv24 = dst_yuv24 + (ptrdiff_t)(height - 1) * dst_stride_yuv24; dst_stride_yuv24 = -dst_stride_yuv24; } #if defined(HAS_NV21TOYUV24ROW_NEON) @@ -4825,13 +4860,14 @@ int YUY2ToARGBMatrix(const uint8_t* src_yuy2, void (*YUY2ToARGBRow)(const uint8_t* src_yuy2, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width) = YUY2ToARGBRow_C; - if (!src_yuy2 || !dst_argb || width <= 0 || height == 0) { + if (!src_yuy2 || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_yuy2 = src_yuy2 + (height - 1) * src_stride_yuy2; + src_yuy2 = src_yuy2 + (ptrdiff_t)(height - 1) * src_stride_yuy2; src_stride_yuy2 = -src_stride_yuy2; } // Coalesce rows. @@ -4916,13 +4952,14 @@ int UYVYToARGBMatrix(const uint8_t* src_uyvy, void (*UYVYToARGBRow)(const uint8_t* src_uyvy, uint8_t* dst_argb, const struct YuvConstants* yuvconstants, int width) = UYVYToARGBRow_C; - if (!src_uyvy || !dst_argb || width <= 0 || height == 0) { + if (!src_uyvy || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_uyvy = src_uyvy + (height - 1) * src_stride_uyvy; + src_uyvy = src_uyvy + (ptrdiff_t)(height - 1) * src_stride_uyvy; src_stride_uyvy = -src_stride_uyvy; } // Coalesce rows. @@ -5029,14 +5066,15 @@ int Android420ToARGBMatrix(const uint8_t* src_y, int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; assert(yuvconstants); - if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; halfheight = (height + 1) >> 1; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } @@ -5135,13 +5173,14 @@ int I422ToRGBAMatrix(const uint8_t* src_y, const struct YuvConstants* yuvconstants, int width) = I422ToRGBARow_C; assert(yuvconstants); - if (!src_y || !src_u || !src_v || !dst_rgba || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_rgba || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_rgba = dst_rgba + (height - 1) * dst_stride_rgba; + dst_rgba = dst_rgba + (ptrdiff_t)(height - 1) * dst_stride_rgba; dst_stride_rgba = -dst_stride_rgba; } #if defined(HAS_I422TORGBAROW_SSSE3) @@ -5262,13 +5301,14 @@ int NV12ToRGB565Matrix(const uint8_t* src_y, const uint8_t* y_buf, const uint8_t* uv_buf, uint8_t* rgb_buf, const struct YuvConstants* yuvconstants, int width) = NV12ToRGB565Row_C; assert(yuvconstants); - if (!src_y || !src_uv || !dst_rgb565 || width <= 0 || height == 0) { + if (!src_y || !src_uv || !dst_rgb565 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_rgb565 = dst_rgb565 + (height - 1) * dst_stride_rgb565; + dst_rgb565 = dst_rgb565 + (ptrdiff_t)(height - 1) * dst_stride_rgb565; dst_stride_rgb565 = -dst_stride_rgb565; } #if defined(HAS_NV12TORGB565ROW_SSSE3) @@ -5357,13 +5397,14 @@ int I420ToRGBAMatrix(const uint8_t* src_y, const struct YuvConstants* yuvconstants, int width) = I422ToRGBARow_C; assert(yuvconstants); - if (!src_y || !src_u || !src_v || !dst_rgba || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_rgba || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_rgba = dst_rgba + (height - 1) * dst_stride_rgba; + dst_rgba = dst_rgba + (ptrdiff_t)(height - 1) * dst_stride_rgba; dst_stride_rgba = -dst_stride_rgba; } #if defined(HAS_I422TORGBAROW_SSSE3) @@ -5489,13 +5530,14 @@ int I420ToRGB24Matrix(const uint8_t* src_y, const struct YuvConstants* yuvconstants, int width) = I422ToRGB24Row_C; assert(yuvconstants); - if (!src_y || !src_u || !src_v || !dst_rgb24 || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_rgb24 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_rgb24 = dst_rgb24 + (height - 1) * dst_stride_rgb24; + dst_rgb24 = dst_rgb24 + (ptrdiff_t)(height - 1) * dst_stride_rgb24; dst_stride_rgb24 = -dst_stride_rgb24; } #if defined(HAS_I422TORGB24ROW_SSSE3) @@ -5693,13 +5735,14 @@ int I422ToRGB24Matrix(const uint8_t* src_y, const struct YuvConstants* yuvconstants, int width) = I422ToRGB24Row_C; assert(yuvconstants); - if (!src_y || !src_u || !src_v || !dst_rgb24 || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_rgb24 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_rgb24 = dst_rgb24 + (height - 1) * dst_stride_rgb24; + dst_rgb24 = dst_rgb24 + (ptrdiff_t)(height - 1) * dst_stride_rgb24; dst_stride_rgb24 = -dst_stride_rgb24; } #if defined(HAS_I422TORGB24ROW_SSSE3) @@ -5822,13 +5865,13 @@ int I420ToARGB1555(const uint8_t* src_y, const struct YuvConstants* yuvconstants, int width) = I422ToARGB1555Row_C; if (!src_y || !src_u || !src_v || !dst_argb1555 || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb1555 = dst_argb1555 + (height - 1) * dst_stride_argb1555; + dst_argb1555 = dst_argb1555 + (ptrdiff_t)(height - 1) * dst_stride_argb1555; dst_stride_argb1555 = -dst_stride_argb1555; } #if defined(HAS_I422TOARGB1555ROW_SSSE3) @@ -5913,13 +5956,13 @@ int I420ToARGB4444(const uint8_t* src_y, const struct YuvConstants* yuvconstants, int width) = I422ToARGB4444Row_C; if (!src_y || !src_u || !src_v || !dst_argb4444 || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb4444 = dst_argb4444 + (height - 1) * dst_stride_argb4444; + dst_argb4444 = dst_argb4444 + (ptrdiff_t)(height - 1) * dst_stride_argb4444; dst_stride_argb4444 = -dst_stride_argb4444; } #if defined(HAS_I422TOARGB4444ROW_SSSE3) @@ -6005,13 +6048,14 @@ int I420ToRGB565Matrix(const uint8_t* src_y, const struct YuvConstants* yuvconstants, int width) = I422ToRGB565Row_C; assert(yuvconstants); - if (!src_y || !src_u || !src_v || !dst_rgb565 || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_rgb565 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_rgb565 = dst_rgb565 + (height - 1) * dst_stride_rgb565; + dst_rgb565 = dst_rgb565 + (ptrdiff_t)(height - 1) * dst_stride_rgb565; dst_stride_rgb565 = -dst_stride_rgb565; } #if defined(HAS_I422TORGB565ROW_SSSE3) @@ -6147,13 +6191,14 @@ int I422ToRGB565Matrix(const uint8_t* src_y, const struct YuvConstants* yuvconstants, int width) = I422ToRGB565Row_C; assert(yuvconstants); - if (!src_y || !src_u || !src_v || !dst_rgb565 || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_rgb565 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_rgb565 = dst_rgb565 + (height - 1) * dst_stride_rgb565; + dst_rgb565 = dst_rgb565 + (ptrdiff_t)(height - 1) * dst_stride_rgb565; dst_stride_rgb565 = -dst_stride_rgb565; } #if defined(HAS_I422TORGB565ROW_SSSE3) @@ -6260,13 +6305,14 @@ int I420ToRGB565Dither(const uint8_t* src_y, void (*ARGBToRGB565DitherRow)(const uint8_t* src_argb, uint8_t* dst_rgb, uint32_t dither4, int width) = ARGBToRGB565DitherRow_C; - if (!src_y || !src_u || !src_v || !dst_rgb565 || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_rgb565 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_rgb565 = dst_rgb565 + (height - 1) * dst_stride_rgb565; + dst_rgb565 = dst_rgb565 + (ptrdiff_t)(height - 1) * dst_stride_rgb565; dst_stride_rgb565 = -dst_stride_rgb565; } if (!dither4x4) { @@ -6423,13 +6469,14 @@ int I420ToAR30Matrix(const uint8_t* src_y, I422ToAR30Row_C; assert(yuvconstants); - if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_ar30 = dst_ar30 + (height - 1) * dst_stride_ar30; + dst_ar30 = dst_ar30 + (ptrdiff_t)(height - 1) * dst_stride_ar30; dst_stride_ar30 = -dst_stride_ar30; } @@ -6570,13 +6617,14 @@ static int I420ToARGBMatrixBilinear(const uint8_t* src_y, void (*ScaleRowUp2_Linear)(const uint8_t* src_ptr, uint8_t* dst_ptr, int dst_width) = ScaleRowUp2_Linear_Any_C; assert(yuvconstants); - if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } #if defined(HAS_I444TOARGBROW_SSSE3) @@ -6719,13 +6767,14 @@ static int I422ToARGBMatrixLinear(const uint8_t* src_y, void (*ScaleRowUp2_Linear)(const uint8_t* src_ptr, uint8_t* dst_ptr, int dst_width) = ScaleRowUp2_Linear_Any_C; assert(yuvconstants); - if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } #if defined(HAS_I444TOARGBROW_SSSE3) @@ -6845,13 +6894,14 @@ static int I420ToRGB24MatrixBilinear(const uint8_t* src_y, void (*ScaleRowUp2_Linear)(const uint8_t* src_ptr, uint8_t* dst_ptr, int dst_width) = ScaleRowUp2_Linear_Any_C; assert(yuvconstants); - if (!src_y || !src_u || !src_v || !dst_rgb24 || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_rgb24 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_rgb24 = dst_rgb24 + (height - 1) * dst_stride_rgb24; + dst_rgb24 = dst_rgb24 + (ptrdiff_t)(height - 1) * dst_stride_rgb24; dst_stride_rgb24 = -dst_stride_rgb24; } #if defined(HAS_I444TORGB24ROW_SSSE3) @@ -6997,13 +7047,14 @@ static int I010ToAR30MatrixBilinear(const uint16_t* src_y, void (*ScaleRowUp2_Linear_12)(const uint16_t* src_ptr, uint16_t* dst_ptr, int dst_width) = ScaleRowUp2_Linear_16_Any_C; assert(yuvconstants); - if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_ar30 = dst_ar30 + (height - 1) * dst_stride_ar30; + dst_ar30 = dst_ar30 + (ptrdiff_t)(height - 1) * dst_stride_ar30; dst_stride_ar30 = -dst_stride_ar30; } #if defined(HAS_I410TOAR30ROW_NEON) @@ -7121,13 +7172,14 @@ static int I210ToAR30MatrixLinear(const uint16_t* src_y, void (*ScaleRowUp2_Linear_12)(const uint16_t* src_ptr, uint16_t* dst_ptr, int dst_width) = ScaleRowUp2_Linear_16_Any_C; assert(yuvconstants); - if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_ar30 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_ar30 = dst_ar30 + (height - 1) * dst_stride_ar30; + dst_ar30 = dst_ar30 + (ptrdiff_t)(height - 1) * dst_stride_ar30; dst_stride_ar30 = -dst_stride_ar30; } #if defined(HAS_I410TOAR30ROW_NEON) @@ -7224,13 +7276,14 @@ static int I010ToARGBMatrixBilinear(const uint16_t* src_y, void (*ScaleRowUp2_Linear_12)(const uint16_t* src_ptr, uint16_t* dst_ptr, int dst_width) = ScaleRowUp2_Linear_16_Any_C; assert(yuvconstants); - if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } #if defined(HAS_I410TOARGBROW_SSSE3) @@ -7347,13 +7400,14 @@ static int I210ToARGBMatrixLinear(const uint16_t* src_y, void (*ScaleRowUp2_Linear_12)(const uint16_t* src_ptr, uint16_t* dst_ptr, int dst_width) = ScaleRowUp2_Linear_16_Any_C; assert(yuvconstants); - if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } #if defined(HAS_I410TOARGBROW_SSSE3) @@ -7459,13 +7513,13 @@ static int I420AlphaToARGBMatrixBilinear( int dst_width) = ScaleRowUp2_Linear_Any_C; assert(yuvconstants); if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } #if defined(HAS_I444ALPHATOARGBROW_SSSE3) @@ -7679,13 +7733,13 @@ static int I422AlphaToARGBMatrixLinear(const uint8_t* src_y, int dst_width) = ScaleRowUp2_Linear_Any_C; assert(yuvconstants); if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } #if defined(HAS_I444ALPHATOARGBROW_SSSE3) @@ -7864,13 +7918,13 @@ static int I010AlphaToARGBMatrixBilinear( int dst_width) = ScaleRowUp2_Linear_16_Any_C; assert(yuvconstants); if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } #if defined(HAS_I410ALPHATOARGBROW_NEON) @@ -8058,13 +8112,13 @@ static int I210AlphaToARGBMatrixLinear(const uint16_t* src_y, int dst_width) = ScaleRowUp2_Linear_16_Any_C; assert(yuvconstants); if (!src_y || !src_u || !src_v || !src_a || !dst_argb || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } #if defined(HAS_I410ALPHATOARGBROW_NEON) @@ -8206,13 +8260,14 @@ static int P010ToARGBMatrixBilinear(const uint16_t* src_y, const uint16_t* src_ptr, ptrdiff_t src_stride, uint16_t* dst_ptr, ptrdiff_t dst_stride, int dst_width) = ScaleUVRowUp2_Bilinear_16_Any_C; assert(yuvconstants); - if (!src_y || !src_uv || !dst_argb || width <= 0 || height == 0) { + if (!src_y || !src_uv || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } #if defined(HAS_P410TOARGBROW_SSSE3) @@ -8317,13 +8372,14 @@ static int P210ToARGBMatrixLinear(const uint16_t* src_y, void (*ScaleRowUp2_Linear)(const uint16_t* src_uv, uint16_t* dst_uv, int dst_width) = ScaleUVRowUp2_Linear_16_Any_C; assert(yuvconstants); - if (!src_y || !src_uv || !dst_argb || width <= 0 || height == 0) { + if (!src_y || !src_uv || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } #if defined(HAS_P410TOARGBROW_SSSE3) @@ -8414,13 +8470,14 @@ static int P010ToAR30MatrixBilinear(const uint16_t* src_y, const uint16_t* src_ptr, ptrdiff_t src_stride, uint16_t* dst_ptr, ptrdiff_t dst_stride, int dst_width) = ScaleUVRowUp2_Bilinear_16_Any_C; assert(yuvconstants); - if (!src_y || !src_uv || !dst_ar30 || width <= 0 || height == 0) { + if (!src_y || !src_uv || !dst_ar30 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_ar30 = dst_ar30 + (height - 1) * dst_stride_ar30; + dst_ar30 = dst_ar30 + (ptrdiff_t)(height - 1) * dst_stride_ar30; dst_stride_ar30 = -dst_stride_ar30; } #if defined(HAS_P410TOAR30ROW_SSSE3) @@ -8525,13 +8582,14 @@ static int P210ToAR30MatrixLinear(const uint16_t* src_y, void (*ScaleRowUp2_Linear)(const uint16_t* src_uv, uint16_t* dst_uv, int dst_width) = ScaleUVRowUp2_Linear_16_Any_C; assert(yuvconstants); - if (!src_y || !src_uv || !dst_ar30 || width <= 0 || height == 0) { + if (!src_y || !src_uv || !dst_ar30 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_ar30 = dst_ar30 + (height - 1) * dst_stride_ar30; + dst_ar30 = dst_ar30 + (ptrdiff_t)(height - 1) * dst_stride_ar30; dst_stride_ar30 = -dst_stride_ar30; } #if defined(HAS_P410TOAR30ROW_SSSE3) @@ -8624,13 +8682,14 @@ static int I422ToRGB24MatrixLinear(const uint8_t* src_y, void (*ScaleRowUp2_Linear)(const uint8_t* src_ptr, uint8_t* dst_ptr, int dst_width) = ScaleRowUp2_Linear_Any_C; assert(yuvconstants); - if (!src_y || !src_u || !src_v || !dst_rgb24 || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_rgb24 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_rgb24 = dst_rgb24 + (height - 1) * dst_stride_rgb24; + dst_rgb24 = dst_rgb24 + (ptrdiff_t)(height - 1) * dst_stride_rgb24; dst_stride_rgb24 = -dst_stride_rgb24; } #if defined(HAS_I444TORGB24ROW_SSSE3) diff --git a/source/convert_from.cc b/source/convert_from.cc index aa5de62f5..40ca02190 100644 --- a/source/convert_from.cc +++ b/source/convert_from.cc @@ -89,16 +89,16 @@ int I420ToI010(const uint8_t* src_y, int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; halfheight = (height + 1) >> 1; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (halfheight - 1) * src_stride_u; - src_v = src_v + (halfheight - 1) * src_stride_v; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(halfheight - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(halfheight - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; @@ -134,16 +134,16 @@ int I420ToI012(const uint8_t* src_y, int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; halfheight = (height + 1) >> 1; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (halfheight - 1) * src_stride_u; - src_v = src_v + (halfheight - 1) * src_stride_v; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(halfheight - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(halfheight - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; @@ -228,7 +228,7 @@ int I010ToI410(const uint16_t* src_y, int height) { int r; if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } @@ -265,7 +265,7 @@ int I210ToI410(const uint16_t* src_y, int height) { int r; if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } @@ -301,7 +301,7 @@ int I422ToI444(const uint8_t* src_y, int height) { int r; if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } @@ -326,7 +326,7 @@ int I400Copy(const uint8_t* src_y, int dst_stride_y, int width, int height) { - if (!src_y || !dst_y || width <= 0 || height == 0) { + if (!src_y || !dst_y || width <= 0 || height == 0 || height == INT_MIN) { return -1; } CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); @@ -348,13 +348,14 @@ int I422ToYUY2(const uint8_t* src_y, void (*I422ToYUY2Row)(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_yuy2, int width) = I422ToYUY2Row_C; - if (!src_y || !src_u || !src_v || !dst_yuy2 || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_yuy2 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_yuy2 = dst_yuy2 + (height - 1) * dst_stride_yuy2; + dst_yuy2 = dst_yuy2 + (ptrdiff_t)(height - 1) * dst_stride_yuy2; dst_stride_yuy2 = -dst_stride_yuy2; } // Coalesce rows. @@ -415,13 +416,14 @@ int I420ToYUY2(const uint8_t* src_y, void (*I422ToYUY2Row)(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_yuy2, int width) = I422ToYUY2Row_C; - if (!src_y || !src_u || !src_v || !dst_yuy2 || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_yuy2 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_yuy2 = dst_yuy2 + (height - 1) * dst_stride_yuy2; + dst_yuy2 = dst_yuy2 + (ptrdiff_t)(height - 1) * dst_stride_yuy2; dst_stride_yuy2 = -dst_stride_yuy2; } #if defined(HAS_I422TOYUY2ROW_SSE2) @@ -495,13 +497,14 @@ int I422ToUYVY(const uint8_t* src_y, void (*I422ToUYVYRow)(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_uyvy, int width) = I422ToUYVYRow_C; - if (!src_y || !src_u || !src_v || !dst_uyvy || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_uyvy || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_uyvy = dst_uyvy + (height - 1) * dst_stride_uyvy; + dst_uyvy = dst_uyvy + (ptrdiff_t)(height - 1) * dst_stride_uyvy; dst_stride_uyvy = -dst_stride_uyvy; } // Coalesce rows. @@ -578,13 +581,14 @@ int I420ToUYVY(const uint8_t* src_y, void (*I422ToUYVYRow)(const uint8_t* src_y, const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_uyvy, int width) = I422ToUYVYRow_C; - if (!src_y || !src_u || !src_v || !dst_uyvy || width <= 0 || height == 0) { + if (!src_y || !src_u || !src_v || !dst_uyvy || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_uyvy = dst_uyvy + (height - 1) * dst_stride_uyvy; + dst_uyvy = dst_uyvy + (ptrdiff_t)(height - 1) * dst_stride_uyvy; dst_stride_uyvy = -dst_stride_uyvy; } #if defined(HAS_I422TOUYVYROW_SSE2) @@ -659,16 +663,16 @@ int I420ToNV12(const uint8_t* src_y, int halfwidth = (width + 1) / 2; int halfheight = (height + 1) / 2; if ((!src_y && dst_y) || !src_u || !src_v || !dst_uv || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; halfheight = (height + 1) >> 1; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (halfheight - 1) * src_stride_u; - src_v = src_v + (halfheight - 1) * src_stride_v; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(halfheight - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(halfheight - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; @@ -714,7 +718,8 @@ int ConvertFromI420(const uint8_t* y, uint32_t fourcc) { uint32_t format = CanonicalFourCC(fourcc); int r = 0; - if (!y || !u || !v || !dst_sample || width <= 0 || height == 0) { + if (!y || !u || !v || !dst_sample || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } switch (format) { diff --git a/source/convert_from_argb.cc b/source/convert_from_argb.cc index 08a0cd825..d912f4537 100644 --- a/source/convert_from_argb.cc +++ b/source/convert_from_argb.cc @@ -154,13 +154,13 @@ ARGBToUV444MatrixRow_C; } #endif if (!src_argb || !dst_y || !dst_u || !dst_v || !argbconstants || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } @@ -329,13 +329,13 @@ ARGBToUVMatrixRow_C; } #endif if (!src_argb || !dst_y || !dst_u || !dst_v || !argbconstants || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } @@ -493,13 +493,13 @@ ARGBToUVMatrixRow_C; void (*MergeUVRow)(const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_uv, int width) = MergeUVRow_C; if (!src_argb || !dst_y || !dst_uv || !argbconstants || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } #if defined(HAS_MERGEUVROW_SSE2) @@ -708,13 +708,13 @@ ARGBToUVMatrixRow_C; void (*MergeUVRow)(const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_vu, int width) = MergeUVRow_C; if (!src_argb || !dst_y || !dst_vu || !argbconstants || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } #if defined(HAS_MERGEUVROW_SSE2) @@ -804,12 +804,13 @@ int ARGBToI400Matrix(const uint8_t* src_argb, int y; void (*ARGBToYMatrixRow)(const uint8_t* src_argb, uint8_t* dst_y, int width, const struct ArgbConstants* c) = ARGBToYMatrixRow_C; - if (!src_argb || !dst_y || !constants || width <= 0 || height == 0) { + if (!src_argb || !dst_y || !constants || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } #if defined(HAS_ARGBTOYMATRIXROW_AVX2) @@ -870,12 +871,13 @@ int ARGBToYUY2Matrix(const uint8_t* src_argb, const uint8_t* src_v, uint8_t* dst_yuy2, int width) = I422ToYUY2Row_C; - if (!src_argb || !dst_yuy2 || !constants || width <= 0 || height == 0) { + if (!src_argb || !dst_yuy2 || !constants || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } if (height < 0) { height = -height; - dst_yuy2 = dst_yuy2 + (height - 1) * dst_stride_yuy2; + dst_yuy2 = dst_yuy2 + (ptrdiff_t)(height - 1) * dst_stride_yuy2; dst_stride_yuy2 = -dst_stride_yuy2; } #if defined(HAS_ARGBTOYMATRIXROW_AVX2) @@ -981,12 +983,13 @@ int ARGBToUYVYMatrix(const uint8_t* src_argb, const uint8_t* src_v, uint8_t* dst_uyvy, int width) = I422ToUYVYRow_C; - if (!src_argb || !dst_uyvy || !constants || width <= 0 || height == 0) { + if (!src_argb || !dst_uyvy || !constants || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } if (height < 0) { height = -height; - dst_uyvy = dst_uyvy + (height - 1) * dst_stride_uyvy; + dst_uyvy = dst_uyvy + (ptrdiff_t)(height - 1) * dst_stride_uyvy; dst_stride_uyvy = -dst_stride_uyvy; } #if defined(HAS_ARGBTOYMATRIXROW_AVX2) @@ -1181,12 +1184,13 @@ int ARGBToRGBA(const uint8_t* src_argb, int y; void (*ARGBToRGBARow)(const uint8_t* src_argb, uint8_t* dst_rgba, int width) = ARGBToRGBARow_C; - if (!src_argb || !dst_rgba || width <= 0 || height == 0) { + if (!src_argb || !dst_rgba || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. @@ -1223,12 +1227,13 @@ int ARGBToRGB24(const uint8_t* src_argb, int y; void (*ARGBToRGB24Row)(const uint8_t* src_argb, uint8_t* dst_rgb, int width) = ARGBToRGB24Row_C; - if (!src_argb || !dst_rgb24 || width <= 0 || height == 0) { + if (!src_argb || !dst_rgb24 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. @@ -1316,12 +1321,12 @@ int ARGBToRAW(const uint8_t* src_argb, int y; void (*ARGBToRAWRow)(const uint8_t* src_argb, uint8_t* dst_rgb, int width) = ARGBToRAWRow_C; - if (!src_argb || !dst_raw || width <= 0 || height == 0) { + if (!src_argb || !dst_raw || width <= 0 || height == 0 || height == INT_MIN) { return -1; } if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. @@ -1408,12 +1413,13 @@ int ARGBToRGB565Dither(const uint8_t* src_argb, void (*ARGBToRGB565DitherRow)(const uint8_t* src_argb, uint8_t* dst_rgb, uint32_t dither4, int width) = ARGBToRGB565DitherRow_C; - if (!src_argb || !dst_rgb565 || width <= 0 || height == 0) { + if (!src_argb || !dst_rgb565 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } if (!dither4x4) { @@ -1480,12 +1486,13 @@ int ARGBToRGB565(const uint8_t* src_argb, int y; void (*ARGBToRGB565Row)(const uint8_t* src_argb, uint8_t* dst_rgb, int width) = ARGBToRGB565Row_C; - if (!src_argb || !dst_rgb565 || width <= 0 || height == 0) { + if (!src_argb || !dst_rgb565 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. @@ -1554,12 +1561,13 @@ int ARGBToARGB1555(const uint8_t* src_argb, int y; void (*ARGBToARGB1555Row)(const uint8_t* src_argb, uint8_t* dst_rgb, int width) = ARGBToARGB1555Row_C; - if (!src_argb || !dst_argb1555 || width <= 0 || height == 0) { + if (!src_argb || !dst_argb1555 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. @@ -1622,12 +1630,13 @@ int ARGBToARGB4444(const uint8_t* src_argb, int y; void (*ARGBToARGB4444Row)(const uint8_t* src_argb, uint8_t* dst_rgb, int width) = ARGBToARGB4444Row_C; - if (!src_argb || !dst_argb4444 || width <= 0 || height == 0) { + if (!src_argb || !dst_argb4444 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. @@ -1690,12 +1699,13 @@ int ABGRToAR30(const uint8_t* src_abgr, int y; void (*ABGRToAR30Row)(const uint8_t* src_abgr, uint8_t* dst_rgb, int width) = ABGRToAR30Row_C; - if (!src_abgr || !dst_ar30 || width <= 0 || height == 0) { + if (!src_abgr || !dst_ar30 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } if (height < 0) { height = -height; - src_abgr = src_abgr + (height - 1) * src_stride_abgr; + src_abgr = src_abgr + (ptrdiff_t)(height - 1) * src_stride_abgr; src_stride_abgr = -src_stride_abgr; } // Coalesce rows. @@ -1748,12 +1758,13 @@ int ARGBToAR30(const uint8_t* src_argb, int y; void (*ARGBToAR30Row)(const uint8_t* src_argb, uint8_t* dst_rgb, int width) = ARGBToAR30Row_C; - if (!src_argb || !dst_ar30 || width <= 0 || height == 0) { + if (!src_argb || !dst_ar30 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. @@ -1869,12 +1880,12 @@ int RGBAToJ400(const uint8_t* src_rgba, int y; void (*RGBAToYJRow)(const uint8_t* src_rgba, uint8_t* dst_yj, int width) = RGBAToYJRow_C; - if (!src_rgba || !dst_yj || width <= 0 || height == 0) { + if (!src_rgba || !dst_yj || width <= 0 || height == 0 || height == INT_MIN) { return -1; } if (height < 0) { height = -height; - src_rgba = src_rgba + (height - 1) * src_stride_rgba; + src_rgba = src_rgba + (ptrdiff_t)(height - 1) * src_stride_rgba; src_stride_rgba = -src_stride_rgba; } // Coalesce rows. @@ -2011,13 +2022,14 @@ int ARGBToAR64(const uint8_t* src_argb, int y; void (*ARGBToAR64Row)(const uint8_t* src_argb, uint16_t* dst_ar64, int width) = ARGBToAR64Row_C; - if (!src_argb || !dst_ar64 || width <= 0 || height == 0) { + if (!src_argb || !dst_ar64 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. @@ -2076,13 +2088,14 @@ int ARGBToAB64(const uint8_t* src_argb, int y; void (*ARGBToAB64Row)(const uint8_t* src_argb, uint16_t* dst_ar64, int width) = ARGBToAB64Row_C; - if (!src_argb || !dst_ab64 || width <= 0 || height == 0) { + if (!src_argb || !dst_ab64 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. @@ -2215,14 +2228,14 @@ int RAWToNV21Matrix(const uint8_t* src_raw, } #endif - - if (!src_raw || !dst_y || !dst_vu || !argbconstants || width <= 0 || height == 0) { + if (!src_raw || !dst_y || !dst_vu || !argbconstants || width <= 0 || + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_raw = src_raw + (height - 1) * src_stride_raw; + src_raw = src_raw + (ptrdiff_t)(height - 1) * src_stride_raw; src_stride_raw = -src_stride_raw; } diff --git a/source/convert_to_argb.cc b/source/convert_to_argb.cc index 72d21b042..4b465b276 100644 --- a/source/convert_to_argb.cc +++ b/source/convert_to_argb.cc @@ -72,7 +72,8 @@ int ConvertToARGB(const uint8_t* sample, if (dst_argb == NULL || sample == NULL || src_width <= 0 || src_width > INT_MAX / 4 || crop_width <= 0 || crop_width > INT_MAX / 4 || - src_height == 0 || crop_height == 0) { + src_height == 0 || src_height == INT_MIN || crop_height == 0 || + crop_height == INT_MIN) { return -1; } if (src_height < 0) { diff --git a/source/convert_to_i420.cc b/source/convert_to_i420.cc index 96b2afbcc..8441928fb 100644 --- a/source/convert_to_i420.cc +++ b/source/convert_to_i420.cc @@ -66,7 +66,8 @@ int ConvertToI420(const uint8_t* sample, if (!dst_y || !dst_u || !dst_v || !sample || src_width <= 0 || src_width > INT_MAX / 4 || crop_width <= 0 || src_height == 0 || - crop_height == 0 || crop_x < 0 || crop_y < 0 || crop_width > src_width || + src_height == INT_MIN || crop_height == 0 || crop_height == INT_MIN || + crop_x < 0 || crop_y < 0 || crop_width > src_width || crop_x > src_width - crop_width || abs_crop_height > abs_src_height || crop_y > abs_src_height - abs_crop_height) { return -1; diff --git a/source/planar_functions.cc b/source/planar_functions.cc index 5bd5fd911..cff7c5d0a 100644 --- a/source/planar_functions.cc +++ b/source/planar_functions.cc @@ -34,13 +34,13 @@ void CopyPlane(const uint8_t* src_y, int height) { int y; void (*CopyRow)(const uint8_t* src, uint8_t* dst, int width) = CopyRow_C; - if (width <= 0 || height == 0) { + if (width <= 0 || height == 0 || height == INT_MIN) { return; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_y = dst_y + (height - 1) * dst_stride_y; + dst_y = dst_y + (ptrdiff_t)(height - 1) * dst_stride_y; dst_stride_y = -dst_stride_y; } // Coalesce rows. @@ -123,13 +123,13 @@ void Convert16To8Plane(const uint16_t* src_y, void (*Convert16To8Row)(const uint16_t* src_y, uint8_t* dst_y, int scale, int width) = Convert16To8Row_C; - if (width <= 0 || height == 0) { + if (width <= 0 || height == 0 || height == INT_MIN) { return; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_y = dst_y + (height - 1) * dst_stride_y; + dst_y = dst_y + (ptrdiff_t)(height - 1) * dst_stride_y; dst_stride_y = -dst_stride_y; } // Coalesce rows. @@ -198,13 +198,13 @@ void Convert8To16Plane(const uint8_t* src_y, void (*Convert8To16Row)(const uint8_t* src_y, uint16_t* dst_y, int scale, int width) = Convert8To16Row_C; - if (width <= 0 || height == 0) { + if (width <= 0 || height == 0 || height == INT_MIN) { return; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_y = dst_y + (height - 1) * dst_stride_y; + dst_y = dst_y + (ptrdiff_t)(height - 1) * dst_stride_y; dst_stride_y = -dst_stride_y; } // Coalesce rows. @@ -266,13 +266,13 @@ void Convert8To8Plane(const uint8_t* src_y, void (*Convert8To8Row)(const uint8_t* src_y, uint8_t* dst_y, int scale, int bias, int width) = Convert8To8Row_C; - if (width <= 0 || height == 0) { + if (width <= 0 || height == 0 || height == INT_MIN) { return; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_y = dst_y + (height - 1) * dst_stride_y; + dst_y = dst_y + (ptrdiff_t)(height - 1) * dst_stride_y; dst_stride_y = -dst_stride_y; } // Coalesce rows. @@ -336,16 +336,16 @@ int I422Copy(const uint8_t* src_y, int halfwidth = (width + 1) >> 1; if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (height - 1) * src_stride_u; - src_v = src_v + (height - 1) * src_stride_v; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(height - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(height - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; @@ -376,15 +376,15 @@ int I444Copy(const uint8_t* src_y, int width, int height) { if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (height - 1) * src_stride_u; - src_v = src_v + (height - 1) * src_stride_v; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(height - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(height - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; @@ -417,16 +417,16 @@ int I210Copy(const uint16_t* src_y, int halfwidth = (width + 1) >> 1; if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (height - 1) * src_stride_u; - src_v = src_v + (height - 1) * src_stride_v; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(height - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(height - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; @@ -458,15 +458,15 @@ int I410Copy(const uint16_t* src_y, int width, int height) { if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (height - 1) * src_stride_u; - src_v = src_v + (height - 1) * src_stride_v; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(height - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(height - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; @@ -488,13 +488,13 @@ int I400ToI400(const uint8_t* src_y, int dst_stride_y, int width, int height) { - if (!src_y || !dst_y || width <= 0 || height == 0) { + if (!src_y || !dst_y || width <= 0 || height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_y = src_y + (height - 1) * src_stride_y; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; src_stride_y = -src_stride_y; } CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); @@ -517,13 +517,13 @@ int I420ToI400(const uint8_t* src_y, (void)src_stride_u; (void)src_v; (void)src_stride_v; - if (!src_y || !dst_y || width <= 0 || height == 0) { + if (!src_y || !dst_y || width <= 0 || height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_y = src_y + (height - 1) * src_stride_y; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; src_stride_y = -src_stride_y; } @@ -546,7 +546,8 @@ int NV12Copy(const uint8_t* src_y, int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; - if (!src_y || !dst_y || !src_uv || !dst_uv || width <= 0 || height == 0) { + if (!src_y || !dst_y || !src_uv || !dst_uv || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } @@ -554,8 +555,8 @@ int NV12Copy(const uint8_t* src_y, if (height < 0) { height = -height; halfheight = (height + 1) >> 1; - src_y = src_y + (height - 1) * src_stride_y; - src_uv = src_uv + (halfheight - 1) * src_stride_uv; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_uv = src_uv + (ptrdiff_t)(halfheight - 1) * src_stride_uv; src_stride_y = -src_stride_y; src_stride_uv = -src_stride_uv; } @@ -595,14 +596,14 @@ void SplitUVPlane(const uint8_t* src_uv, int y; void (*SplitUVRow)(const uint8_t* src_uv, uint8_t* dst_u, uint8_t* dst_v, int width) = SplitUVRow_C; - if (width <= 0 || height == 0) { + if (width <= 0 || height == 0 || height == INT_MIN) { return; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_u = dst_u + (height - 1) * dst_stride_u; - dst_v = dst_v + (height - 1) * dst_stride_v; + dst_u = dst_u + (ptrdiff_t)(height - 1) * dst_stride_u; + dst_v = dst_v + (ptrdiff_t)(height - 1) * dst_stride_v; dst_stride_u = -dst_stride_u; dst_stride_v = -dst_stride_v; } @@ -672,13 +673,13 @@ void MergeUVPlane(const uint8_t* src_u, int y; void (*MergeUVRow)(const uint8_t* src_u, const uint8_t* src_v, uint8_t* dst_uv, int width) = MergeUVRow_C; - if (width <= 0 || height == 0) { + if (width <= 0 || height == 0 || height == INT_MIN) { return; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_uv = dst_uv + (height - 1) * dst_stride_uv; + dst_uv = dst_uv + (ptrdiff_t)(height - 1) * dst_stride_uv; dst_stride_uv = -dst_stride_uv; } // Coalesce rows. @@ -764,14 +765,14 @@ void SplitUVPlane_16(const uint16_t* src_uv, void (*SplitUVRow_16)(const uint16_t* src_uv, uint16_t* dst_u, uint16_t* dst_v, int depth, int width) = SplitUVRow_16_C; - if (width <= 0 || height == 0) { + if (width <= 0 || height == 0 || height == INT_MIN) { return; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_u = dst_u + (height - 1) * dst_stride_u; - dst_v = dst_v + (height - 1) * dst_stride_v; + dst_u = dst_u + (ptrdiff_t)(height - 1) * dst_stride_u; + dst_v = dst_v + (ptrdiff_t)(height - 1) * dst_stride_v; dst_stride_u = -dst_stride_u; dst_stride_v = -dst_stride_v; } @@ -824,13 +825,13 @@ void MergeUVPlane_16(const uint16_t* src_u, MergeUVRow_16_C; assert(depth >= 8); assert(depth <= 16); - if (width <= 0 || height == 0) { + if (width <= 0 || height == 0 || height == INT_MIN) { return; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_uv = dst_uv + (height - 1) * dst_stride_uv; + dst_uv = dst_uv + (ptrdiff_t)(height - 1) * dst_stride_uv; dst_stride_uv = -dst_stride_uv; } // Coalesce rows. @@ -884,13 +885,13 @@ void ConvertToMSBPlane_16(const uint16_t* src_y, int scale = 1 << (16 - depth); void (*MultiplyRow_16)(const uint16_t* src_y, uint16_t* dst_y, int scale, int width) = MultiplyRow_16_C; - if (width <= 0 || height == 0) { + if (width <= 0 || height == 0 || height == INT_MIN) { return; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_y = dst_y + (height - 1) * dst_stride_y; + dst_y = dst_y + (ptrdiff_t)(height - 1) * dst_stride_y; dst_stride_y = -dst_stride_y; } // Coalesce rows. @@ -943,13 +944,13 @@ void ConvertToLSBPlane_16(const uint16_t* src_y, int scale = 1 << depth; void (*DivideRow)(const uint16_t* src_y, uint16_t* dst_y, int scale, int width) = DivideRow_16_C; - if (width <= 0 || height == 0) { + if (width <= 0 || height == 0 || height == INT_MIN) { return; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_y = dst_y + (height - 1) * dst_stride_y; + dst_y = dst_y + (ptrdiff_t)(height - 1) * dst_stride_y; dst_stride_y = -dst_stride_y; } // Coalesce rows. @@ -1000,13 +1001,13 @@ void SwapUVPlane(const uint8_t* src_uv, int y; void (*SwapUVRow)(const uint8_t* src_uv, uint8_t* dst_vu, int width) = SwapUVRow_C; - if (width <= 0 || height == 0) { + if (width <= 0 || height == 0 || height == INT_MIN) { return; } // Negative height means invert the image. if (height < 0) { height = -height; - src_uv = src_uv + (height - 1) * src_stride_uv; + src_uv = src_uv + (ptrdiff_t)(height - 1) * src_stride_uv; src_stride_uv = -src_stride_uv; } // Coalesce rows. @@ -1064,7 +1065,7 @@ int NV21ToNV12(const uint8_t* src_y, int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; - if (!src_vu || !dst_uv || width <= 0 || height == 0) { + if (!src_vu || !dst_uv || width <= 0 || height == 0 || height == INT_MIN) { return -1; } @@ -1076,7 +1077,7 @@ int NV21ToNV12(const uint8_t* src_y, if (height < 0) { height = -height; halfheight = (height + 1) >> 1; - src_vu = src_vu + (halfheight - 1) * src_stride_vu; + src_vu = src_vu + (ptrdiff_t)(halfheight - 1) * src_stride_vu; src_stride_vu = -src_stride_vu; } @@ -1105,7 +1106,7 @@ int DetilePlane(const uint8_t* src_y, int y; void (*DetileRow)(const uint8_t* src, ptrdiff_t src_tile_stride, uint8_t* dst, int width) = DetileRow_C; - if (!src_y || !dst_y || width <= 0 || height == 0 || + if (!src_y || !dst_y || width <= 0 || height == 0 || height == INT_MIN || !IS_POWEROFTWO(tile_height)) { return -1; } @@ -1113,7 +1114,7 @@ int DetilePlane(const uint8_t* src_y, // Negative height means invert the image. if (height < 0) { height = -height; - dst_y = dst_y + (height - 1) * dst_stride_y; + dst_y = dst_y + (ptrdiff_t)(height - 1) * dst_stride_y; dst_stride_y = -dst_stride_y; } @@ -1162,7 +1163,7 @@ int DetilePlane_16(const uint16_t* src_y, int y; void (*DetileRow_16)(const uint16_t* src, ptrdiff_t src_tile_stride, uint16_t* dst, int width) = DetileRow_16_C; - if (!src_y || !dst_y || width <= 0 || height == 0 || + if (!src_y || !dst_y || width <= 0 || height == 0 || height == INT_MIN || !IS_POWEROFTWO(tile_height)) { return -1; } @@ -1170,7 +1171,7 @@ int DetilePlane_16(const uint16_t* src_y, // Negative height means invert the image. if (height < 0) { height = -height; - dst_y = dst_y + (height - 1) * dst_stride_y; + dst_y = dst_y + (ptrdiff_t)(height - 1) * dst_stride_y; dst_stride_y = -dst_stride_y; } @@ -1231,15 +1232,15 @@ void DetileSplitUVPlane(const uint8_t* src_uv, assert(tile_height > 0); assert(src_stride_uv > 0); - if (width <= 0 || height == 0) { + if (width <= 0 || height == 0 || height == INT_MIN) { return; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_u = dst_u + (height - 1) * dst_stride_u; + dst_u = dst_u + (ptrdiff_t)(height - 1) * dst_stride_u; dst_stride_u = -dst_stride_u; - dst_v = dst_v + (height - 1) * dst_stride_v; + dst_v = dst_v + (ptrdiff_t)(height - 1) * dst_stride_v; dst_stride_v = -dst_stride_v; } @@ -1295,13 +1296,13 @@ void DetileToYUY2(const uint8_t* src_y, assert(src_stride_uv > 0); assert(tile_height > 0); - if (width <= 0 || height == 0 || tile_height <= 0) { + if (width <= 0 || height == 0 || height == INT_MIN || tile_height <= 0) { return; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_yuy2 = dst_yuy2 + (height - 1) * dst_stride_yuy2; + dst_yuy2 = dst_yuy2 + (ptrdiff_t)(height - 1) * dst_stride_yuy2; dst_stride_yuy2 = -dst_stride_yuy2; } @@ -1357,15 +1358,15 @@ void SplitRGBPlane(const uint8_t* src_rgb, int y; void (*SplitRGBRow)(const uint8_t* src_rgb, uint8_t* dst_r, uint8_t* dst_g, uint8_t* dst_b, int width) = SplitRGBRow_C; - if (width <= 0 || height == 0) { + if (width <= 0 || height == 0 || height == INT_MIN) { return; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_r = dst_r + (height - 1) * dst_stride_r; - dst_g = dst_g + (height - 1) * dst_stride_g; - dst_b = dst_b + (height - 1) * dst_stride_b; + dst_r = dst_r + (ptrdiff_t)(height - 1) * dst_stride_r; + dst_g = dst_g + (ptrdiff_t)(height - 1) * dst_stride_g; + dst_b = dst_b + (ptrdiff_t)(height - 1) * dst_stride_b; dst_stride_r = -dst_stride_r; dst_stride_g = -dst_stride_g; dst_stride_b = -dst_stride_b; @@ -1441,14 +1442,14 @@ void MergeRGBPlane(const uint8_t* src_r, void (*MergeRGBRow)(const uint8_t* src_r, const uint8_t* src_g, const uint8_t* src_b, uint8_t* dst_rgb, int width) = MergeRGBRow_C; - if (width <= 0 || height == 0) { + if (width <= 0 || height == 0 || height == INT_MIN) { return; } // Coalesce rows. // Negative height means invert the image. if (height < 0) { height = -height; - dst_rgb = dst_rgb + (height - 1) * dst_stride_rgb; + dst_rgb = dst_rgb + (ptrdiff_t)(height - 1) * dst_stride_rgb; dst_stride_rgb = -dst_stride_rgb; } // Coalesce rows. @@ -1657,13 +1658,16 @@ void SplitARGBPlane(const uint8_t* src_argb, int dst_stride_a, int width, int height) { + if (width <= 0 || height == 0 || height == INT_MIN) { + return; + } // Negative height means invert the image. if (height < 0) { height = -height; - dst_r = dst_r + (height - 1) * dst_stride_r; - dst_g = dst_g + (height - 1) * dst_stride_g; - dst_b = dst_b + (height - 1) * dst_stride_b; - dst_a = dst_a + (height - 1) * dst_stride_a; + dst_r = dst_r + (ptrdiff_t)(height - 1) * dst_stride_r; + dst_g = dst_g + (ptrdiff_t)(height - 1) * dst_stride_g; + dst_b = dst_b + (ptrdiff_t)(height - 1) * dst_stride_b; + dst_a = dst_a + (ptrdiff_t)(height - 1) * dst_stride_a; dst_stride_r = -dst_stride_r; dst_stride_g = -dst_stride_g; dst_stride_b = -dst_stride_b; @@ -1830,10 +1834,13 @@ void MergeARGBPlane(const uint8_t* src_r, int dst_stride_argb, int width, int height) { + if (width <= 0 || height == 0 || height == INT_MIN) { + return; + } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } @@ -1866,13 +1873,13 @@ void MergeXR30Plane(const uint16_t* src_r, const uint16_t* src_b, uint8_t* dst_ar30, int depth, int width) = MergeXR30Row_C; - if (width <= 0 || height == 0) { + if (width <= 0 || height == 0 || height == INT_MIN) { return; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_ar30 = dst_ar30 + (height - 1) * dst_stride_ar30; + dst_ar30 = dst_ar30 + (ptrdiff_t)(height - 1) * dst_stride_ar30; dst_stride_ar30 = -dst_stride_ar30; } // Coalesce rows. @@ -2044,10 +2051,13 @@ void MergeAR64Plane(const uint16_t* src_r, int width, int height, int depth) { + if (width <= 0 || height == 0 || height == INT_MIN) { + return; + } // Negative height means invert the image. if (height < 0) { height = -height; - dst_ar64 = dst_ar64 + (height - 1) * dst_stride_ar64; + dst_ar64 = dst_ar64 + (ptrdiff_t)(height - 1) * dst_stride_ar64; dst_stride_ar64 = -dst_stride_ar64; } @@ -2191,10 +2201,13 @@ void MergeARGB16To8Plane(const uint16_t* src_r, int width, int height, int depth) { + if (width <= 0 || height == 0 || height == INT_MIN) { + return; + } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } @@ -2226,13 +2239,14 @@ int YUY2ToI422(const uint8_t* src_yuy2, uint8_t* dst_v, int width) = YUY2ToUV422Row_C; void (*YUY2ToYRow)(const uint8_t* src_yuy2, uint8_t* dst_y, int width) = YUY2ToYRow_C; - if (!src_yuy2 || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0) { + if (!src_yuy2 || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_yuy2 = src_yuy2 + (height - 1) * src_stride_yuy2; + src_yuy2 = src_yuy2 + (ptrdiff_t)(height - 1) * src_stride_yuy2; src_stride_yuy2 = -src_stride_yuy2; } // Coalesce rows. @@ -2322,13 +2336,14 @@ int UYVYToI422(const uint8_t* src_uyvy, uint8_t* dst_v, int width) = UYVYToUV422Row_C; void (*UYVYToYRow)(const uint8_t* src_uyvy, uint8_t* dst_y, int width) = UYVYToYRow_C; - if (!src_uyvy || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0) { + if (!src_uyvy || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_uyvy = src_uyvy + (height - 1) * src_stride_uyvy; + src_uyvy = src_uyvy + (ptrdiff_t)(height - 1) * src_stride_uyvy; src_stride_uyvy = -src_stride_uyvy; } // Coalesce rows. @@ -2412,13 +2427,13 @@ int YUY2ToY(const uint8_t* src_yuy2, int y; void (*YUY2ToYRow)(const uint8_t* src_yuy2, uint8_t* dst_y, int width) = YUY2ToYRow_C; - if (!src_yuy2 || !dst_y || width <= 0 || height == 0) { + if (!src_yuy2 || !dst_y || width <= 0 || height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_yuy2 = src_yuy2 + (height - 1) * src_stride_yuy2; + src_yuy2 = src_yuy2 + (ptrdiff_t)(height - 1) * src_stride_yuy2; src_stride_yuy2 = -src_stride_yuy2; } // Coalesce rows. @@ -2472,13 +2487,13 @@ int UYVYToY(const uint8_t* src_uyvy, int y; void (*UYVYToYRow)(const uint8_t* src_uyvy, uint8_t* dst_y, int width) = UYVYToYRow_C; - if (!src_uyvy || !dst_y || width <= 0 || height == 0) { + if (!src_uyvy || !dst_y || width <= 0 || height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_uyvy = src_uyvy + (height - 1) * src_stride_uyvy; + src_uyvy = src_uyvy + (ptrdiff_t)(height - 1) * src_stride_uyvy; src_stride_uyvy = -src_stride_uyvy; } // Coalesce rows. @@ -2540,10 +2555,13 @@ void MirrorPlane(const uint8_t* src_y, int height) { int y; void (*MirrorRow)(const uint8_t* src, uint8_t* dst, int width) = MirrorRow_C; + if (width <= 0 || height == 0 || height == INT_MIN) { + return; + } // Negative height means invert the image. if (height < 0) { height = -height; - src_y = src_y + (height - 1) * src_stride_y; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; src_stride_y = -src_stride_y; } #if defined(HAS_MIRRORROW_NEON) @@ -2606,10 +2624,13 @@ void MirrorUVPlane(const uint8_t* src_uv, int y; void (*MirrorUVRow)(const uint8_t* src, uint8_t* dst, int width) = MirrorUVRow_C; + if (width <= 0 || height == 0 || height == INT_MIN) { + return; + } // Negative height means invert the image. if (height < 0) { height = -height; - src_uv = src_uv + (height - 1) * src_stride_uv; + src_uv = src_uv + (ptrdiff_t)(height - 1) * src_stride_uv; src_stride_uv = -src_stride_uv; } #if defined(HAS_MIRRORUVROW_NEON) @@ -2668,13 +2689,13 @@ int I400Mirror(const uint8_t* src_y, int dst_stride_y, int width, int height) { - if (!src_y || !dst_y || width <= 0 || height == 0) { + if (!src_y || !dst_y || width <= 0 || height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_y = src_y + (height - 1) * src_stride_y; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; src_stride_y = -src_stride_y; } @@ -2702,7 +2723,7 @@ int I420Mirror(const uint8_t* src_y, int halfheight = (height + 1) >> 1; if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } @@ -2710,9 +2731,9 @@ int I420Mirror(const uint8_t* src_y, if (height < 0) { height = -height; halfheight = (height + 1) >> 1; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (halfheight - 1) * src_stride_u; - src_v = src_v + (halfheight - 1) * src_stride_v; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(halfheight - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(halfheight - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; @@ -2741,7 +2762,8 @@ int NV12Mirror(const uint8_t* src_y, int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; - if ((!src_y && dst_y) || !src_uv || !dst_uv || width <= 0 || height == 0) { + if ((!src_y && dst_y) || !src_uv || !dst_uv || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } @@ -2749,8 +2771,8 @@ int NV12Mirror(const uint8_t* src_y, if (height < 0) { height = -height; halfheight = (height + 1) >> 1; - src_y = src_y + (height - 1) * src_stride_y; - src_uv = src_uv + (halfheight - 1) * src_stride_uv; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_uv = src_uv + (ptrdiff_t)(halfheight - 1) * src_stride_uv; src_stride_y = -src_stride_y; src_stride_uv = -src_stride_uv; } @@ -2774,13 +2796,14 @@ int ARGBMirror(const uint8_t* src_argb, int y; void (*ARGBMirrorRow)(const uint8_t* src, uint8_t* dst, int width) = ARGBMirrorRow_C; - if (!src_argb || !dst_argb || width <= 0 || height == 0) { + if (!src_argb || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } #if defined(HAS_ARGBMIRRORROW_NEON) @@ -2844,13 +2867,14 @@ int RGB24Mirror(const uint8_t* src_rgb24, int y; void (*RGB24MirrorRow)(const uint8_t* src, uint8_t* dst, int width) = RGB24MirrorRow_C; - if (!src_rgb24 || !dst_rgb24 || width <= 0 || height == 0) { + if (!src_rgb24 || !dst_rgb24 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_rgb24 = src_rgb24 + (height - 1) * src_stride_rgb24; + src_rgb24 = src_rgb24 + (ptrdiff_t)(height - 1) * src_stride_rgb24; src_stride_rgb24 = -src_stride_rgb24; } #if defined(HAS_RGB24MIRRORROW_NEON) @@ -2892,13 +2916,14 @@ int ARGBBlend(const uint8_t* src_argb0, int y; void (*ARGBBlendRow)(const uint8_t* src_argb, const uint8_t* src_argb1, uint8_t* dst_argb, int width) = ARGBBlendRow_C; - if (!src_argb0 || !src_argb1 || !dst_argb || width <= 0 || height == 0) { + if (!src_argb0 || !src_argb1 || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } // Coalesce rows. @@ -2953,13 +2978,14 @@ int BlendPlane(const uint8_t* src_y0, void (*BlendPlaneRow)(const uint8_t* src0, const uint8_t* src1, const uint8_t* alpha, uint8_t* dst, int width) = BlendPlaneRow_C; - if (!src_y0 || !src_y1 || !alpha || !dst_y || width <= 0 || height == 0) { + if (!src_y0 || !src_y1 || !alpha || !dst_y || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_y = dst_y + (height - 1) * dst_stride_y; + dst_y = dst_y + (ptrdiff_t)(height - 1) * dst_stride_y; dst_stride_y = -dst_stride_y; } @@ -3039,14 +3065,15 @@ int I420Blend(const uint8_t* src_y0, uint8_t* dst_ptr, int dst_width) = ScaleRowDown2Box_C; if (!src_y0 || !src_u0 || !src_v0 || !src_y1 || !src_u1 || !src_v1 || - !alpha || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0) { + !alpha || !dst_y || !dst_u || !dst_v || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_y = dst_y + (height - 1) * dst_stride_y; + dst_y = dst_y + (ptrdiff_t)(height - 1) * dst_stride_y; dst_stride_y = -dst_stride_y; } @@ -3155,13 +3182,14 @@ int ARGBMultiply(const uint8_t* src_argb0, int y; void (*ARGBMultiplyRow)(const uint8_t* src0, const uint8_t* src1, uint8_t* dst, int width) = ARGBMultiplyRow_C; - if (!src_argb0 || !src_argb1 || !dst_argb || width <= 0 || height == 0) { + if (!src_argb0 || !src_argb1 || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } // Coalesce rows. @@ -3240,13 +3268,14 @@ int ARGBAdd(const uint8_t* src_argb0, int y; void (*ARGBAddRow)(const uint8_t* src0, const uint8_t* src1, uint8_t* dst, int width) = ARGBAddRow_C; - if (!src_argb0 || !src_argb1 || !dst_argb || width <= 0 || height == 0) { + if (!src_argb0 || !src_argb1 || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } // Coalesce rows. @@ -3325,13 +3354,14 @@ int ARGBSubtract(const uint8_t* src_argb0, int y; void (*ARGBSubtractRow)(const uint8_t* src0, const uint8_t* src1, uint8_t* dst, int width) = ARGBSubtractRow_C; - if (!src_argb0 || !src_argb1 || !dst_argb || width <= 0 || height == 0) { + if (!src_argb0 || !src_argb1 || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } // Coalesce rows. @@ -3403,13 +3433,14 @@ int RAWToRGB24(const uint8_t* src_raw, int y; void (*RAWToRGB24Row)(const uint8_t* src_rgb, uint8_t* dst_rgb24, int width) = RAWToRGB24Row_C; - if (!src_raw || !dst_rgb24 || width <= 0 || height == 0) { + if (!src_raw || !dst_rgb24 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_raw = src_raw + (height - 1) * src_stride_raw; + src_raw = src_raw + (ptrdiff_t)(height - 1) * src_stride_raw; src_stride_raw = -src_stride_raw; } // Coalesce rows. @@ -3472,12 +3503,12 @@ void SetPlane(uint8_t* dst_y, int y; void (*SetRow)(uint8_t* dst, uint8_t value, int width) = SetRow_C; - if (width <= 0 || height == 0) { + if (width <= 0 || height == 0 || height == INT_MIN) { return; } if (height < 0) { height = -height; - dst_y = dst_y + (height - 1) * dst_stride_y; + dst_y = dst_y + (ptrdiff_t)(height - 1) * dst_stride_y; dst_stride_y = -dst_stride_y; } // Coalesce rows. @@ -3544,9 +3575,9 @@ int I420Rect(uint8_t* dst_y, uint8_t* start_u = dst_u + (y / 2) * dst_stride_u + (x / 2); uint8_t* start_v = dst_v + (y / 2) * dst_stride_v + (x / 2); - if (!dst_y || !dst_u || !dst_v || width <= 0 || height == 0 || x < 0 || - y < 0 || value_y < 0 || value_y > 255 || value_u < 0 || value_u > 255 || - value_v < 0 || value_v > 255) { + if (!dst_y || !dst_u || !dst_v || width <= 0 || height == 0 || + height == INT_MIN || x < 0 || y < 0 || value_y < 0 || value_y > 255 || + value_u < 0 || value_u > 255 || value_v < 0 || value_v > 255) { return -1; } @@ -3568,12 +3599,13 @@ int ARGBRect(uint8_t* dst_argb, int y; void (*ARGBSetRow)(uint8_t* dst_argb, uint32_t value, int width) = ARGBSetRow_C; - if (!dst_argb || width <= 0 || height == 0 || dst_x < 0 || dst_y < 0) { + if (!dst_argb || width <= 0 || height == 0 || height == INT_MIN || + dst_x < 0 || dst_y < 0) { return -1; } if (height < 0) { height = -height; - dst_argb = dst_argb + (height - 1) * dst_stride_argb; + dst_argb = dst_argb + (ptrdiff_t)(height - 1) * dst_stride_argb; dst_stride_argb = -dst_stride_argb; } dst_argb += dst_y * dst_stride_argb + dst_x * 4; @@ -3637,12 +3669,13 @@ int ARGBAttenuate(const uint8_t* src_argb, int y; void (*ARGBAttenuateRow)(const uint8_t* src_argb, uint8_t* dst_argb, int width) = ARGBAttenuateRow_C; - if (!src_argb || !dst_argb || width <= 0 || height == 0) { + if (!src_argb || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. @@ -3717,12 +3750,13 @@ int ARGBUnattenuate(const uint8_t* src_argb, int y; void (*ARGBUnattenuateRow)(const uint8_t* src_argb, uint8_t* dst_argb, int width) = ARGBUnattenuateRow_C; - if (!src_argb || !dst_argb || width <= 0 || height == 0) { + if (!src_argb || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. @@ -3769,12 +3803,13 @@ int ARGBGrayTo(const uint8_t* src_argb, int y; void (*ARGBGrayRow)(const uint8_t* src_argb, uint8_t* dst_argb, int width) = ARGBGrayRow_C; - if (!src_argb || !dst_argb || width <= 0 || height == 0) { + if (!src_argb || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. @@ -3939,12 +3974,13 @@ int ARGBColorMatrix(const uint8_t* src_argb, void (*ARGBColorMatrixRow)(const uint8_t* src_argb, uint8_t* dst_argb, const int8_t* matrix_argb, int width) = ARGBColorMatrixRow_C; - if (!src_argb || !dst_argb || !matrix_argb || width <= 0 || height == 0) { + if (!src_argb || !dst_argb || !matrix_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. @@ -4204,12 +4240,13 @@ int ARGBBlur(const uint8_t* src_argb, int32_t* max_cumsum_bot_row; int32_t* cumsum_top_row; - if (!src_argb || !dst_argb || width <= 0 || height == 0) { + if (!src_argb || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } if (radius > height) { @@ -4304,12 +4341,13 @@ int ARGBShade(const uint8_t* src_argb, int y; void (*ARGBShadeRow)(const uint8_t* src_argb, uint8_t* dst_argb, int width, uint32_t value) = ARGBShadeRow_C; - if (!src_argb || !dst_argb || width <= 0 || height == 0 || value == 0u) { + if (!src_argb || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN || value == 0u) { return -1; } if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. @@ -4363,13 +4401,14 @@ int InterpolatePlane(const uint8_t* src0, void (*InterpolateRow)(uint8_t* dst_ptr, const uint8_t* src_ptr, ptrdiff_t src_stride, int dst_width, int source_y_fraction) = InterpolateRow_C; - if (!src0 || !src1 || !dst || width <= 0 || height == 0) { + if (!src0 || !src1 || !dst || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst = dst + (height - 1) * dst_stride; + dst = dst + (ptrdiff_t)(height - 1) * dst_stride; dst_stride = -dst_stride; } // Coalesce rows. @@ -4438,13 +4477,14 @@ int InterpolatePlane_16(const uint16_t* src0, void (*InterpolateRow_16)(uint16_t* dst_ptr, const uint16_t* src_ptr, ptrdiff_t src_stride, int dst_width, int source_y_fraction) = InterpolateRow_16_C; - if (!src0 || !src1 || !dst || width <= 0 || height == 0) { + if (!src0 || !src1 || !dst || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - dst = dst + (height - 1) * dst_stride; + dst = dst + (ptrdiff_t)(height - 1) * dst_stride; dst_stride = -dst_stride; } // Coalesce rows. @@ -4544,7 +4584,8 @@ int I420Interpolate(const uint8_t* src0_y, int halfheight = (height + 1) >> 1; if (!src0_y || !src0_u || !src0_v || !src1_y || !src1_u || !src1_v || - !dst_y || !dst_u || !dst_v || width <= 0 || height == 0) { + !dst_y || !dst_u || !dst_v || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } @@ -4569,13 +4610,14 @@ int ARGBShuffle(const uint8_t* src_argb, int y; void (*ARGBShuffleRow)(const uint8_t* src_argb, uint8_t* dst_argb, const uint8_t* shuffler, int width) = ARGBShuffleRow_C; - if (!src_argb || !dst_argb || width <= 0 || height == 0) { + if (!src_argb || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. @@ -4654,13 +4696,14 @@ int AR64Shuffle(const uint16_t* src_ar64, int y; void (*AR64ShuffleRow)(const uint8_t* src_ar64, uint8_t* dst_ar64, const uint8_t* shuffler, int width) = AR64ShuffleRow_C; - if (!src_ar64 || !dst_ar64 || width <= 0 || height == 0) { + if (!src_ar64 || !dst_ar64 || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_ar64 = src_ar64 + (height - 1) * src_stride_ar64; + src_ar64 = src_ar64 + (ptrdiff_t)(height - 1) * src_stride_ar64; src_stride_ar64 = -src_stride_ar64; } // Coalesce rows. @@ -4732,13 +4775,13 @@ int GaussPlane_F32(const float* src, int width) = GaussCol_F32_C; void (*GaussRow_F32)(const float* src, float* dst, int width) = GaussRow_F32_C; - if (!src || !dst || width <= 0 || height == 0) { + if (!src || !dst || width <= 0 || height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src = src + (height - 1) * src_stride; + src = src + (ptrdiff_t)(height - 1) * src_stride; src_stride = -src_stride; } @@ -4809,13 +4852,14 @@ static int ARGBSobelize(const uint8_t* src_argb, const uint8_t* src_y2, uint8_t* dst_sobely, int width) = SobelXRow_C; const int kEdge = 16; // Extra pixels at start of row for extrude/align. - if (!src_argb || !dst_argb || width <= 0 || height == 0) { + if (!src_argb || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } @@ -5070,13 +5114,14 @@ int ARGBPolynomial(const uint8_t* src_argb, int y; void (*ARGBPolynomialRow)(const uint8_t* src_argb, uint8_t* dst_argb, const float* poly, int width) = ARGBPolynomialRow_C; - if (!src_argb || !dst_argb || !poly || width <= 0 || height == 0) { + if (!src_argb || !dst_argb || !poly || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. @@ -5119,7 +5164,7 @@ int HalfFloatPlane(const uint16_t* src_y, int y; void (*HalfFloatRow)(const uint16_t* src, uint16_t* dst, float scale, int width) = HalfFloatRow_C; - if (!src_y || !dst_y || width <= 0 || height == 0) { + if (!src_y || !dst_y || width <= 0 || height == 0 || height == INT_MIN) { return -1; } src_stride_y >>= 1; @@ -5127,7 +5172,7 @@ int HalfFloatPlane(const uint16_t* src_y, // Negative height means invert the image. if (height < 0) { height = -height; - src_y = src_y + (height - 1) * src_stride_y; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; src_stride_y = -src_stride_y; } // Coalesce rows. @@ -5226,13 +5271,14 @@ int ARGBLumaColorTable(const uint8_t* src_argb, void (*ARGBLumaColorTableRow)( const uint8_t* src_argb, uint8_t* dst_argb, int width, const uint8_t* luma, const uint32_t lumacoeff) = ARGBLumaColorTableRow_C; - if (!src_argb || !dst_argb || !luma || width <= 0 || height == 0) { + if (!src_argb || !dst_argb || !luma || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. @@ -5267,13 +5313,14 @@ int ARGBCopyAlpha(const uint8_t* src_argb, int y; void (*ARGBCopyAlphaRow)(const uint8_t* src_argb, uint8_t* dst_argb, int width) = ARGBCopyAlphaRow_C; - if (!src_argb || !dst_argb || width <= 0 || height == 0) { + if (!src_argb || !dst_argb || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. @@ -5316,13 +5363,13 @@ int ARGBExtractAlpha(const uint8_t* src_argb, int dst_stride_a, int width, int height) { - if (!src_argb || !dst_a || width <= 0 || height == 0) { + if (!src_argb || !dst_a || width <= 0 || height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb += (height - 1) * src_stride_argb; + src_argb += (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } // Coalesce rows. @@ -5383,13 +5430,13 @@ int ARGBCopyYToAlpha(const uint8_t* src_y, int y; void (*ARGBCopyYToAlphaRow)(const uint8_t* src_y, uint8_t* dst_argb, int width) = ARGBCopyYToAlphaRow_C; - if (!src_y || !dst_argb || width <= 0 || height == 0) { + if (!src_y || !dst_argb || width <= 0 || height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_y = src_y + (height - 1) * src_stride_y; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; src_stride_y = -src_stride_y; } // Coalesce rows. @@ -5443,14 +5490,15 @@ int YUY2ToNV12(const uint8_t* src_yuy2, YUY2ToYRow_C; void (*YUY2ToNVUVRow)(const uint8_t* src_yuy2, int stride_yuy2, uint8_t* dst_uv, int width) = YUY2ToNVUVRow_C; - if (!src_yuy2 || !dst_y || !dst_uv || width <= 0 || height == 0) { + if (!src_yuy2 || !dst_y || !dst_uv || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_yuy2 = src_yuy2 + (height - 1) * src_stride_yuy2; + src_yuy2 = src_yuy2 + (ptrdiff_t)(height - 1) * src_stride_yuy2; src_stride_yuy2 = -src_stride_yuy2; } #if defined(HAS_YUY2TOYROW_SSE2) @@ -5551,14 +5599,15 @@ int UYVYToNV12(const uint8_t* src_uyvy, ptrdiff_t src_stride, int dst_width, int source_y_fraction) = InterpolateRow_C; - if (!src_uyvy || !dst_y || !dst_uv || width <= 0 || height == 0) { + if (!src_uyvy || !dst_y || !dst_uv || width <= 0 || height == 0 || + height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_uyvy = src_uyvy + (height - 1) * src_stride_uyvy; + src_uyvy = src_uyvy + (ptrdiff_t)(height - 1) * src_stride_uyvy; src_stride_uyvy = -src_stride_uyvy; } #if defined(HAS_SPLITUVROW_SSE2) @@ -5677,11 +5726,14 @@ void HalfMergeUVPlane(const uint8_t* src_u, const uint8_t* src_v, int src_stride_v, uint8_t* dst_uv, int width) = HalfMergeUVRow_C; + if (width <= 0 || height == 0 || height == INT_MIN) { + return; + } // Negative height means invert the image. if (height < 0) { height = -height; - src_u = src_u + (height - 1) * src_stride_u; - src_v = src_v + (height - 1) * src_stride_v; + src_u = src_u + (ptrdiff_t)(height - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(height - 1) * src_stride_v; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; } diff --git a/source/rotate.cc b/source/rotate.cc index d51b313be..54e0c2e63 100644 --- a/source/rotate.cc +++ b/source/rotate.cc @@ -9,6 +9,7 @@ */ #include +#include #include "libyuv/rotate.h" @@ -431,14 +432,15 @@ int SplitRotateUV(const uint8_t* src_uv, int width, int height, enum RotationMode mode) { - if (!src_uv || width <= 0 || height == 0 || !dst_u || !dst_v) { + if (!src_uv || width <= 0 || height == 0 || height == INT_MIN || !dst_u || + !dst_v) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_uv = src_uv + (height - 1) * src_stride_uv; + src_uv = src_uv + (ptrdiff_t)(height - 1) * src_stride_uv; src_stride_uv = -src_stride_uv; } @@ -473,14 +475,14 @@ int RotatePlane(const uint8_t* src, int width, int height, enum RotationMode mode) { - if (!src || width <= 0 || height == 0 || !dst) { + if (!src || width <= 0 || height == 0 || height == INT_MIN || !dst) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src = src + (height - 1) * src_stride; + src = src + (ptrdiff_t)(height - 1) * src_stride; src_stride = -src_stride; } @@ -591,14 +593,14 @@ int RotatePlane_16(const uint16_t* src, int width, int height, enum RotationMode mode) { - if (!src || width <= 0 || height == 0 || !dst) { + if (!src || width <= 0 || height == 0 || height == INT_MIN || !dst) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src = src + (height - 1) * src_stride; + src = src + (ptrdiff_t)(height - 1) * src_stride; src_stride = -src_stride; } @@ -641,7 +643,7 @@ int I420Rotate(const uint8_t* src_y, int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; if ((!src_y && dst_y) || !src_u || !src_v || width <= 0 || height == 0 || - !dst_y || !dst_u || !dst_v) { + height == INT_MIN || !dst_y || !dst_u || !dst_v) { return -1; } @@ -649,9 +651,9 @@ int I420Rotate(const uint8_t* src_y, if (height < 0) { height = -height; halfheight = (height + 1) >> 1; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (halfheight - 1) * src_stride_u; - src_v = src_v + (halfheight - 1) * src_stride_v; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(halfheight - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(halfheight - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; @@ -711,16 +713,16 @@ int I422Rotate(const uint8_t* src_y, int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; int r; - if (!src_y || !src_u || !src_v || width <= 0 || height == 0 || !dst_y || - !dst_u || !dst_v) { + if (!src_y || !src_u || !src_v || width <= 0 || height == 0 || + height == INT_MIN || !dst_y || !dst_u || !dst_v) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (height - 1) * src_stride_u; - src_v = src_v + (height - 1) * src_stride_v; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(height - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(height - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; @@ -806,17 +808,17 @@ int I444Rotate(const uint8_t* src_y, int width, int height, enum RotationMode mode) { - if (!src_y || !src_u || !src_v || width <= 0 || height == 0 || !dst_y || - !dst_u || !dst_v) { + if (!src_y || !src_u || !src_v || width <= 0 || height == 0 || + height == INT_MIN || !dst_y || !dst_u || !dst_v) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (height - 1) * src_stride_u; - src_v = src_v + (height - 1) * src_stride_v; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(height - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(height - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; @@ -866,8 +868,8 @@ int NV12ToI420Rotate(const uint8_t* src_y, enum RotationMode mode) { int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; - if (!src_y || !src_uv || width <= 0 || height == 0 || !dst_y || !dst_u || - !dst_v) { + if (!src_y || !src_uv || width <= 0 || height == 0 || height == INT_MIN || + !dst_y || !dst_u || !dst_v) { return -1; } @@ -875,8 +877,8 @@ int NV12ToI420Rotate(const uint8_t* src_y, if (height < 0) { height = -height; halfheight = (height + 1) >> 1; - src_y = src_y + (height - 1) * src_stride_y; - src_uv = src_uv + (halfheight - 1) * src_stride_uv; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_uv = src_uv + (ptrdiff_t)(halfheight - 1) * src_stride_uv; src_stride_y = -src_stride_y; src_stride_uv = -src_stride_uv; } @@ -943,16 +945,16 @@ int Android420ToI420Rotate(const uint8_t* src_y, int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 || - height == 0) { + height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; halfheight = (height + 1) >> 1; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (halfheight - 1) * src_stride_u; - src_v = src_v + (halfheight - 1) * src_stride_v; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(halfheight - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(halfheight - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; @@ -1018,16 +1020,16 @@ int I010Rotate(const uint16_t* src_y, enum RotationMode mode) { int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; - if (!src_y || !src_u || !src_v || width <= 0 || height == 0 || !dst_y || - !dst_u || !dst_v || dst_stride_y < 0) { + if (!src_y || !src_u || !src_v || width <= 0 || height == 0 || + height == INT_MIN || !dst_y || !dst_u || !dst_v || dst_stride_y < 0) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (height - 1) * src_stride_u; - src_v = src_v + (height - 1) * src_stride_v; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(height - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(height - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; @@ -1089,16 +1091,16 @@ int I210Rotate(const uint16_t* src_y, int halfwidth = (width + 1) >> 1; int halfheight = (height + 1) >> 1; int r; - if (!src_y || !src_u || !src_v || width <= 0 || height == 0 || !dst_y || - !dst_u || !dst_v) { + if (!src_y || !src_u || !src_v || width <= 0 || height == 0 || + height == INT_MIN || !dst_y || !dst_u || !dst_v) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (height - 1) * src_stride_u; - src_v = src_v + (height - 1) * src_stride_v; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(height - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(height - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; @@ -1186,16 +1188,16 @@ int I410Rotate(const uint16_t* src_y, int width, int height, enum RotationMode mode) { - if (!src_y || !src_u || !src_v || width <= 0 || height == 0 || !dst_y || - !dst_u || !dst_v || dst_stride_y < 0) { + if (!src_y || !src_u || !src_v || width <= 0 || height == 0 || + height == INT_MIN || !dst_y || !dst_u || !dst_v || dst_stride_y < 0) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_y = src_y + (height - 1) * src_stride_y; - src_u = src_u + (height - 1) * src_stride_u; - src_v = src_v + (height - 1) * src_stride_v; + src_y = src_y + (ptrdiff_t)(height - 1) * src_stride_y; + src_u = src_u + (ptrdiff_t)(height - 1) * src_stride_u; + src_v = src_v + (ptrdiff_t)(height - 1) * src_stride_v; src_stride_y = -src_stride_y; src_stride_u = -src_stride_u; src_stride_v = -src_stride_v; diff --git a/source/rotate_argb.cc b/source/rotate_argb.cc index 8c76ca919..8cfaed034 100644 --- a/source/rotate_argb.cc +++ b/source/rotate_argb.cc @@ -10,6 +10,8 @@ #include "libyuv/rotate_argb.h" +#include + #include "libyuv/convert.h" #include "libyuv/cpu_id.h" #include "libyuv/planar_functions.h" @@ -222,14 +224,15 @@ int ARGBRotate(const uint8_t* src_argb, int width, int height, enum RotationMode mode) { - if (!src_argb || width <= 0 || height == 0 || !dst_argb) { + if (!src_argb || width <= 0 || height == 0 || height == INT_MIN || + !dst_argb) { return -1; } // Negative height means invert the image. if (height < 0) { height = -height; - src_argb = src_argb + (height - 1) * src_stride_argb; + src_argb = src_argb + (ptrdiff_t)(height - 1) * src_stride_argb; src_stride_argb = -src_stride_argb; } diff --git a/source/scale.cc b/source/scale.cc index a1fd63d27..c504365ae 100644 --- a/source/scale.cc +++ b/source/scale.cc @@ -11,6 +11,7 @@ #include "libyuv/scale.h" #include +#include #include #include "libyuv/cpu_id.h" @@ -2230,8 +2231,8 @@ int I420Scale(const uint8_t* src_y, int r; if (!src_y || !src_u || !src_v || src_width <= 0 || src_height == 0 || - src_width > 32768 || src_height > 32768 || !dst_y || !dst_u || !dst_v || - dst_width <= 0 || dst_height <= 0) { + src_height == INT_MIN || src_width > 32768 || src_height > 32768 || + !dst_y || !dst_u || !dst_v || dst_width <= 0 || dst_height <= 0) { return -1; } @@ -2275,8 +2276,8 @@ int I420Scale_16(const uint16_t* src_y, int r; if (!src_y || !src_u || !src_v || src_width <= 0 || src_height == 0 || - src_width > 32768 || src_height > 32768 || !dst_y || !dst_u || !dst_v || - dst_width <= 0 || dst_height <= 0) { + src_height == INT_MIN || src_width > 32768 || src_height > 32768 || + !dst_y || !dst_u || !dst_v || dst_width <= 0 || dst_height <= 0) { return -1; } @@ -2320,8 +2321,8 @@ int I420Scale_12(const uint16_t* src_y, int r; if (!src_y || !src_u || !src_v || src_width <= 0 || src_height == 0 || - src_width > 32768 || src_height > 32768 || !dst_y || !dst_u || !dst_v || - dst_width <= 0 || dst_height <= 0) { + src_height == INT_MIN || src_width > 32768 || src_height > 32768 || + !dst_y || !dst_u || !dst_v || dst_width <= 0 || dst_height <= 0) { return -1; } @@ -2364,8 +2365,8 @@ int I444Scale(const uint8_t* src_y, int r; if (!src_y || !src_u || !src_v || src_width <= 0 || src_height == 0 || - src_width > 32768 || src_height > 32768 || !dst_y || !dst_u || !dst_v || - dst_width <= 0 || dst_height <= 0) { + src_height == INT_MIN || src_width > 32768 || src_height > 32768 || + !dst_y || !dst_u || !dst_v || dst_width <= 0 || dst_height <= 0) { return -1; } @@ -2405,8 +2406,8 @@ int I444Scale_16(const uint16_t* src_y, int r; if (!src_y || !src_u || !src_v || src_width <= 0 || src_height == 0 || - src_width > 32768 || src_height > 32768 || !dst_y || !dst_u || !dst_v || - dst_width <= 0 || dst_height <= 0) { + src_height == INT_MIN || src_width > 32768 || src_height > 32768 || + !dst_y || !dst_u || !dst_v || dst_width <= 0 || dst_height <= 0) { return -1; } @@ -2446,8 +2447,8 @@ int I444Scale_12(const uint16_t* src_y, int r; if (!src_y || !src_u || !src_v || src_width <= 0 || src_height == 0 || - src_width > 32768 || src_height > 32768 || !dst_y || !dst_u || !dst_v || - dst_width <= 0 || dst_height <= 0) { + src_height == INT_MIN || src_width > 32768 || src_height > 32768 || + !dst_y || !dst_u || !dst_v || dst_width <= 0 || dst_height <= 0) { return -1; } @@ -2492,8 +2493,8 @@ int I422Scale(const uint8_t* src_y, int r; if (!src_y || !src_u || !src_v || src_width <= 0 || src_height == 0 || - src_width > 32768 || src_height > 32768 || !dst_y || !dst_u || !dst_v || - dst_width <= 0 || dst_height <= 0) { + src_height == INT_MIN || src_width > 32768 || src_height > 32768 || + !dst_y || !dst_u || !dst_v || dst_width <= 0 || dst_height <= 0) { return -1; } @@ -2535,8 +2536,8 @@ int I422Scale_16(const uint16_t* src_y, int r; if (!src_y || !src_u || !src_v || src_width <= 0 || src_height == 0 || - src_width > 32768 || src_height > 32768 || !dst_y || !dst_u || !dst_v || - dst_width <= 0 || dst_height <= 0) { + src_height == INT_MIN || src_width > 32768 || src_height > 32768 || + !dst_y || !dst_u || !dst_v || dst_width <= 0 || dst_height <= 0) { return -1; } @@ -2578,8 +2579,8 @@ int I422Scale_12(const uint16_t* src_y, int r; if (!src_y || !src_u || !src_v || src_width <= 0 || src_height == 0 || - src_width > 32768 || src_height > 32768 || !dst_y || !dst_u || !dst_v || - dst_width <= 0 || dst_height <= 0) { + src_height == INT_MIN || src_width > 32768 || src_height > 32768 || + !dst_y || !dst_u || !dst_v || dst_width <= 0 || dst_height <= 0) { return -1; } @@ -2622,8 +2623,8 @@ int NV12Scale(const uint8_t* src_y, int r; if (!src_y || !src_uv || src_width <= 0 || src_height == 0 || - src_width > 32768 || src_height > 32768 || !dst_y || !dst_uv || - dst_width <= 0 || dst_height <= 0) { + src_height == INT_MIN || src_width > 32768 || src_height > 32768 || + !dst_y || !dst_uv || dst_width <= 0 || dst_height <= 0) { return -1; } @@ -2654,8 +2655,8 @@ int NV24Scale(const uint8_t* src_y, int r; if (!src_y || !src_uv || src_width <= 0 || src_height == 0 || - src_width > 32768 || src_height > 32768 || !dst_y || !dst_uv || - dst_width <= 0 || dst_height <= 0) { + src_height == INT_MIN || src_width > 32768 || src_height > 32768 || + !dst_y || !dst_uv || dst_width <= 0 || dst_height <= 0) { return -1; } diff --git a/source/scale_argb.cc b/source/scale_argb.cc index 760293d0d..4dc446d5e 100644 --- a/source/scale_argb.cc +++ b/source/scale_argb.cc @@ -779,9 +779,9 @@ int ARGBScaleClip(const uint8_t* src_argb, int clip_width, int clip_height, enum FilterMode filtering) { - if (!src_argb || src_width == 0 || src_height == 0 || !dst_argb || - dst_width <= 0 || dst_height <= 0 || clip_x < 0 || clip_y < 0 || - clip_width > 32768 || clip_height > 32768 || + if (!src_argb || src_width == 0 || src_height == 0 || src_height == INT_MIN || + !dst_argb || dst_width <= 0 || dst_height <= 0 || clip_x < 0 || + clip_y < 0 || clip_width > 32768 || clip_height > 32768 || (clip_x + clip_width) > dst_width || (clip_y + clip_height) > dst_height) { return -1; @@ -802,8 +802,9 @@ int ARGBScale(const uint8_t* src_argb, int dst_width, int dst_height, enum FilterMode filtering) { - if (!src_argb || src_width == 0 || src_height == 0 || src_width > 32768 || - src_height > 32768 || !dst_argb || dst_width <= 0 || dst_height <= 0) { + if (!src_argb || src_width == 0 || src_height == 0 || src_height == INT_MIN || + src_width > 32768 || src_height > 32768 || !dst_argb || dst_width <= 0 || + dst_height <= 0) { return -1; } return ScaleARGB(src_argb, src_stride_argb, src_width, src_height, dst_argb, @@ -835,12 +836,13 @@ int YUVToARGBScaleClip(const uint8_t* src_y, int r; (void)src_fourcc; // TODO(fbarchard): implement and/or assert. (void)dst_fourcc; - const int abs_src_height = (src_height < 0) ? -src_height : src_height; if (!src_y || !src_u || !src_v || !dst_argb || src_width <= 0 || - src_width > INT_MAX / 4 || src_height == 0 || dst_width <= 0 || - dst_height <= 0 || clip_width <= 0 || clip_height <= 0) { + src_width > INT_MAX / 4 || src_height == 0 || src_height == INT_MIN || + dst_width <= 0 || dst_height <= 0 || clip_width <= 0 || + clip_height <= 0) { return -1; } + 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 (argb_buffer_size > SIZE_MAX) { return -1; // Invalid size. diff --git a/source/scale_rgb.cc b/source/scale_rgb.cc index 5e69fe379..6040b364e 100644 --- a/source/scale_rgb.cc +++ b/source/scale_rgb.cc @@ -42,8 +42,8 @@ int RGBScale(const uint8_t* src_rgb, enum FilterMode filtering) { int r; if (!src_rgb || !dst_rgb || src_width <= 0 || src_width > INT_MAX / 4 || - src_height == 0 || dst_width <= 0 || dst_width > INT_MAX / 4 || - dst_height <= 0) { + src_height == 0 || src_height == INT_MIN || dst_width <= 0 || + dst_width > INT_MAX / 4 || dst_height <= 0) { return -1; } const int abs_src_height = (src_height < 0) ? -src_height : src_height; diff --git a/source/scale_uv.cc b/source/scale_uv.cc index b16b591f8..3574bbe7b 100644 --- a/source/scale_uv.cc +++ b/source/scale_uv.cc @@ -885,7 +885,7 @@ static int UVCopy(const uint8_t* src_uv, int dst_stride_uv, int width, int height) { - if (!src_uv || !dst_uv || width <= 0 || height == 0) { + if (!src_uv || !dst_uv || width <= 0 || height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. @@ -905,7 +905,7 @@ static int UVCopy_16(const uint16_t* src_uv, int dst_stride_uv, int width, int height) { - if (!src_uv || !dst_uv || width <= 0 || height == 0) { + if (!src_uv || !dst_uv || width <= 0 || height == 0 || height == INT_MIN) { return -1; } // Negative height means invert the image. @@ -1061,8 +1061,9 @@ int UVScale(const uint8_t* src_uv, int dst_width, int dst_height, enum FilterMode filtering) { - if (!src_uv || src_width <= 0 || src_height == 0 || src_width > 32768 || - src_height > 32768 || !dst_uv || dst_width <= 0 || dst_height <= 0) { + if (!src_uv || src_width <= 0 || src_height == 0 || src_height == INT_MIN || + src_width > 32768 || src_height > 32768 || !dst_uv || dst_width <= 0 || + dst_height <= 0) { return -1; } return ScaleUV(src_uv, src_stride_uv, src_width, src_height, dst_uv, @@ -1084,8 +1085,9 @@ int UVScale_16(const uint16_t* src_uv, enum FilterMode filtering) { int dy = 0; - if (!src_uv || src_width <= 0 || src_height == 0 || src_width > 32768 || - src_height > 32768 || !dst_uv || dst_width <= 0 || dst_height <= 0) { + if (!src_uv || src_width <= 0 || src_height == 0 || src_height == INT_MIN || + src_width > 32768 || src_height > 32768 || !dst_uv || dst_width <= 0 || + dst_height <= 0) { return -1; }