The result might not fit into 32bit if an image has gigantic dimensions and one of the planes has a dominant value (particularly so if said value is big). Fixes Coverity issues #1598399, #1598401, #1598402, #1598403, #1598404.
Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -721,10 +721,10 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) · 720 unmodified lines | |||
| 721 | if (histv[fil]) maxv = fil; | 721 | if (histv[fil]) maxv = fil; |
| 722 | if (histsat[fil]) maxsat = fil; | 722 | if (histsat[fil]) maxsat = fil; |
| 723 | 723 | ||
| 724 | toty += histy[fil] * fil; | 724 | toty += (uint64_t)histy[fil] * fil; |
| 725 | totu += histu[fil] * fil; | 725 | totu += (uint64_t)histu[fil] * fil; |
| 726 | totv += histv[fil] * fil; | 726 | totv += (uint64_t)histv[fil] * fil; |
| 727 | totsat += histsat[fil] * fil; | 727 | totsat += (uint64_t)histsat[fil] * fil; |
| 728 | 728 | ||
| 729 | accy += histy[fil]; | 729 | accy += histy[fil]; |
| 730 | accu += histu[fil]; | 730 | accu += histu[fil]; |
| @@ -745,7 +745,7 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) · 14 unmodified lines | |||
| 745 | maxhue = histhue[0]; | 745 | maxhue = histhue[0]; |
| 746 | medhue = -1; | 746 | medhue = -1; |
| 747 | for (fil = 0; fil < 360; fil++) { | 747 | for (fil = 0; fil < 360; fil++) { |
| 748 | tothue += histhue[fil] * fil; | 748 | tothue += (uint64_t)histhue[fil] * fil; |
| 749 | acchue += histhue[fil]; | 749 | acchue += histhue[fil]; |
| 750 | 750 | ||
| 751 | if (medhue == -1 && acchue > s->cfs / 2) | 751 | if (medhue == -1 && acchue > s->cfs / 2) |