Fixes: signed integer overflow: -831176 * 9539 cannot be represented in type 'int' Fixes: 67869/clusterfuzz-testcase-minimized-ffmpeg_SWS_fuzzer-5117342091640832 The input is 9bit in 16bit, the fuzzer fills all 16bit thus generating "invalid" input No overflow should happen with valid input.
Unified · Split
| @@ -1207,8 +1207,8 @@ yuv2rgba64_1_c_template(SwsContext *c, const int32_t *buf0, · 1206 unmodified lines | |||
| 1207 | 1207 | ||
| 1208 | if (uvalpha < 2048) { | 1208 | if (uvalpha < 2048) { |
| 1209 | for (i = 0; i < ((dstW + 1) >> 1); i++) { | 1209 | for (i = 0; i < ((dstW + 1) >> 1); i++) { |
| 1210 | int Y1 = (buf0[i * 2] ) >> 2; | 1210 | SUINT Y1 = (buf0[i * 2] ) >> 2; |
| 1211 | int Y2 = (buf0[i * 2 + 1]) >> 2; | 1211 | SUINT Y2 = (buf0[i * 2 + 1]) >> 2; |
| 1212 | int U = (ubuf0[i] - (128 << 11)) >> 2; | 1212 | int U = (ubuf0[i] - (128 << 11)) >> 2; |
| 1213 | int V = (vbuf0[i] - (128 << 11)) >> 2; | 1213 | int V = (vbuf0[i] - (128 << 11)) >> 2; |
| 1214 | int R, G, B; | 1214 | int R, G, B; |
| @@ -1232,20 +1232,20 @@ yuv2rgba64_1_c_template(SwsContext *c, const int32_t *buf0, · 17 unmodified lines | |||
| 1232 | G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff; | 1232 | G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff; |
| 1233 | B = U * c->yuv2rgb_u2b_coeff; | 1233 | B = U * c->yuv2rgb_u2b_coeff; |
| 1234 | 1234 | ||
| 1235 | output_pixel(&dest[0], av_clip_uintp2(((R_B + Y1) >> 14) + (1<<15), 16)); | 1235 | output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y1) >> 14) + (1<<15), 16)); |
| 1236 | output_pixel(&dest[1], av_clip_uintp2((( G + Y1) >> 14) + (1<<15), 16)); | 1236 | output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y1) >> 14) + (1<<15), 16)); |
| 1237 | output_pixel(&dest[2], av_clip_uintp2(((B_R + Y1) >> 14) + (1<<15), 16)); | 1237 | output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y1) >> 14) + (1<<15), 16)); |
| 1238 | if (eightbytes) { | 1238 | if (eightbytes) { |
| 1239 | output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14); | 1239 | output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14); |
| 1240 | output_pixel(&dest[4], av_clip_uintp2(((R_B + Y2) >> 14) + (1<<15), 16)); | 1240 | output_pixel(&dest[4], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16)); |
| 1241 | output_pixel(&dest[5], av_clip_uintp2((( G + Y2) >> 14) + (1<<15), 16)); | 1241 | output_pixel(&dest[5], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16)); |
| 1242 | output_pixel(&dest[6], av_clip_uintp2(((B_R + Y2) >> 14) + (1<<15), 16)); | 1242 | output_pixel(&dest[6], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16)); |
| 1243 | output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14); | 1243 | output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14); |
| 1244 | dest += 8; | 1244 | dest += 8; |
| 1245 | } else { | 1245 | } else { |
| 1246 | output_pixel(&dest[3], av_clip_uintp2(((R_B + Y2) >> 14) + (1<<15), 16)); | 1246 | output_pixel(&dest[3], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16)); |
| 1247 | output_pixel(&dest[4], av_clip_uintp2((( G + Y2) >> 14) + (1<<15), 16)); | 1247 | output_pixel(&dest[4], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16)); |
| 1248 | output_pixel(&dest[5], av_clip_uintp2(((B_R + Y2) >> 14) + (1<<15), 16)); | 1248 | output_pixel(&dest[5], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16)); |
| 1249 | dest += 6; | 1249 | dest += 6; |
| 1250 | } | 1250 | } |
| 1251 | } | 1251 | } |
| @@ -1253,8 +1253,8 @@ yuv2rgba64_1_c_template(SwsContext *c, const int32_t *buf0, · 1 unmodified line | |||
| 1253 | const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1]; | 1253 | const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1]; |
| 1254 | int A1 = 0xffff<<14, A2 = 0xffff<<14; | 1254 | int A1 = 0xffff<<14, A2 = 0xffff<<14; |
| 1255 | for (i = 0; i < ((dstW + 1) >> 1); i++) { | 1255 | for (i = 0; i < ((dstW + 1) >> 1); i++) { |
| 1256 | int Y1 = (buf0[i * 2] ) >> 2; | 1256 | SUINT Y1 = (buf0[i * 2] ) >> 2; |
| 1257 | int Y2 = (buf0[i * 2 + 1]) >> 2; | 1257 | SUINT Y2 = (buf0[i * 2 + 1]) >> 2; |
| 1258 | int U = (ubuf0[i] + ubuf1[i] - (128 << 12)) >> 3; | 1258 | int U = (ubuf0[i] + ubuf1[i] - (128 << 12)) >> 3; |
| 1259 | int V = (vbuf0[i] + vbuf1[i] - (128 << 12)) >> 3; | 1259 | int V = (vbuf0[i] + vbuf1[i] - (128 << 12)) >> 3; |
| 1260 | int R, G, B; | 1260 | int R, G, B; |
| @@ -1278,20 +1278,20 @@ yuv2rgba64_1_c_template(SwsContext *c, const int32_t *buf0, · 17 unmodified lines | |||
| 1278 | G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff; | 1278 | G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff; |
| 1279 | B = U * c->yuv2rgb_u2b_coeff; | 1279 | B = U * c->yuv2rgb_u2b_coeff; |
| 1280 | 1280 | ||
| 1281 | output_pixel(&dest[0], av_clip_uintp2(((R_B + Y1) >> 14) + (1<<15), 16)); | 1281 | output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y1) >> 14) + (1<<15), 16)); |
| 1282 | output_pixel(&dest[1], av_clip_uintp2((( G + Y1) >> 14) + (1<<15), 16)); | 1282 | output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y1) >> 14) + (1<<15), 16)); |
| 1283 | output_pixel(&dest[2], av_clip_uintp2(((B_R + Y1) >> 14) + (1<<15), 16)); | 1283 | output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y1) >> 14) + (1<<15), 16)); |
| 1284 | if (eightbytes) { | 1284 | if (eightbytes) { |
| 1285 | output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14); | 1285 | output_pixel(&dest[3], av_clip_uintp2(A1 , 30) >> 14); |
| 1286 | output_pixel(&dest[4], av_clip_uintp2(((R_B + Y2) >> 14) + (1<<15), 16)); | 1286 | output_pixel(&dest[4], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16)); |
| 1287 | output_pixel(&dest[5], av_clip_uintp2((( G + Y2) >> 14) + (1<<15), 16)); | 1287 | output_pixel(&dest[5], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16)); |
| 1288 | output_pixel(&dest[6], av_clip_uintp2(((B_R + Y2) >> 14) + (1<<15), 16)); | 1288 | output_pixel(&dest[6], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16)); |
| 1289 | output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14); | 1289 | output_pixel(&dest[7], av_clip_uintp2(A2 , 30) >> 14); |
| 1290 | dest += 8; | 1290 | dest += 8; |
| 1291 | } else { | 1291 | } else { |
| 1292 | output_pixel(&dest[3], av_clip_uintp2(((R_B + Y2) >> 14) + (1<<15), 16)); | 1292 | output_pixel(&dest[3], av_clip_uintp2(((int)(R_B + Y2) >> 14) + (1<<15), 16)); |
| 1293 | output_pixel(&dest[4], av_clip_uintp2((( G + Y2) >> 14) + (1<<15), 16)); | 1293 | output_pixel(&dest[4], av_clip_uintp2(((int)( G + Y2) >> 14) + (1<<15), 16)); |
| 1294 | output_pixel(&dest[5], av_clip_uintp2(((B_R + Y2) >> 14) + (1<<15), 16)); | 1294 | output_pixel(&dest[5], av_clip_uintp2(((int)(B_R + Y2) >> 14) + (1<<15), 16)); |
| 1295 | dest += 6; | 1295 | dest += 6; |
| 1296 | } | 1296 | } |
| 1297 | } | 1297 | } |