History

swscale/output: Fix integer overflow in yuv2rgba64_full_1_c_template()

Fixes: signed integer overflow: -1082982400 + -1079364728 cannot be represented in type 'int' Fixes: 67910/clusterfuzz-testcase-minimized-ffmpeg_SWS_fuzzer-5329011971522560 The input is 9bit in 16bit, the fuzzer fills all 16bit thus generating "invalid" input No overflow should happen with valid input.

Michael Niedermayer committed 2 years ago

Commit 1330a731 parent a56559e1 file · +8 −8Browse files

Unified · Split

libswscale/output.c+8−8
@@ -1429,7 +1429,7 @@ yuv2rgba64_full_1_c_template(SwsContext *c, const int32_t *buf0, · 1428 unmodified lines
1429 1429
1430 if (uvalpha < 2048) {1430 if (uvalpha < 2048) {
1431 for (i = 0; i < dstW; i++) {1431 for (i = 0; i < dstW; i++) {
1432 int Y = (buf0[i]) >> 2;1432 SUINT Y = (buf0[i]) >> 2;
1433 int U = (ubuf0[i] - (128 << 11)) >> 2;1433 int U = (ubuf0[i] - (128 << 11)) >> 2;
1434 int V = (vbuf0[i] - (128 << 11)) >> 2;1434 int V = (vbuf0[i] - (128 << 11)) >> 2;
1435 int R, G, B;1435 int R, G, B;
@@ -1448,9 +1448,9 @@ yuv2rgba64_full_1_c_template(SwsContext *c, const int32_t *buf0, · 12 unmodified lines
1448 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;1448 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1449 B = U * c->yuv2rgb_u2b_coeff;1449 B = U * c->yuv2rgb_u2b_coeff;
1450 1450
1451 output_pixel(&dest[0], av_clip_uintp2(((R_B + Y) >> 14) + (1<<15), 16));1451 output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y) >> 14) + (1<<15), 16));
1452 output_pixel(&dest[1], av_clip_uintp2((( G + Y) >> 14) + (1<<15), 16));1452 output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y) >> 14) + (1<<15), 16));
1453 output_pixel(&dest[2], av_clip_uintp2(((B_R + Y) >> 14) + (1<<15), 16));1453 output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y) >> 14) + (1<<15), 16));
1454 if (eightbytes) {1454 if (eightbytes) {
1455 output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);1455 output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
1456 dest += 4;1456 dest += 4;
@@ -1462,7 +1462,7 @@ yuv2rgba64_full_1_c_template(SwsContext *c, const int32_t *buf0, · 5 unmodified lines
1462 const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];1462 const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
1463 int A = 0xffff<<14;1463 int A = 0xffff<<14;
1464 for (i = 0; i < dstW; i++) {1464 for (i = 0; i < dstW; i++) {
1465 int Y = (buf0[i] ) >> 2;1465 SUINT Y = (buf0[i] ) >> 2;
1466 int U = (ubuf0[i] + ubuf1[i] - (128 << 12)) >> 3;1466 int U = (ubuf0[i] + ubuf1[i] - (128 << 12)) >> 3;
1467 int V = (vbuf0[i] + vbuf1[i] - (128 << 12)) >> 3;1467 int V = (vbuf0[i] + vbuf1[i] - (128 << 12)) >> 3;
1468 int R, G, B;1468 int R, G, B;
@@ -1481,9 +1481,9 @@ yuv2rgba64_full_1_c_template(SwsContext *c, const int32_t *buf0, · 12 unmodified lines
1481 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;1481 G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
1482 B = U * c->yuv2rgb_u2b_coeff;1482 B = U * c->yuv2rgb_u2b_coeff;
1483 1483
1484 output_pixel(&dest[0], av_clip_uintp2(((R_B + Y) >> 14) + (1<<15), 16));1484 output_pixel(&dest[0], av_clip_uintp2(((int)(R_B + Y) >> 14) + (1<<15), 16));
1485 output_pixel(&dest[1], av_clip_uintp2((( G + Y) >> 14) + (1<<15), 16));1485 output_pixel(&dest[1], av_clip_uintp2(((int)( G + Y) >> 14) + (1<<15), 16));
1486 output_pixel(&dest[2], av_clip_uintp2(((B_R + Y) >> 14) + (1<<15), 16));1486 output_pixel(&dest[2], av_clip_uintp2(((int)(B_R + Y) >> 14) + (1<<15), 16));
1487 if (eightbytes) {1487 if (eightbytes) {
1488 output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);1488 output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
1489 dest += 4;1489 dest += 4;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t