diff mbox series

[FFmpeg-devel,1/4] avfilter/vf_signalstats: Use 64bit for processing histogram

Message ID GV1P250MB0737F928754691B8AEE671958FF52@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM
State Accepted
Commit dfd0320e23e39ce1362fcb1f919d3f6d6c8a0b53
Headers show
Series [FFmpeg-devel,1/4] avfilter/vf_signalstats: Use 64bit for processing histogram | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt May 24, 2024, 8:04 a.m. UTC
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.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavfilter/vf_signalstats.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

Andreas Rheinhardt May 27, 2024, 5:18 p.m. UTC | #1
Andreas Rheinhardt:
> 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.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavfilter/vf_signalstats.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/libavfilter/vf_signalstats.c b/libavfilter/vf_signalstats.c
> index 50c9df4298..78a23bb705 100644
> --- a/libavfilter/vf_signalstats.c
> +++ b/libavfilter/vf_signalstats.c
> @@ -721,10 +721,10 @@ static int filter_frame(AVFilterLink *link, AVFrame *in)
>          if (histv[fil])   maxv   = fil;
>          if (histsat[fil]) maxsat = fil;
>  
> -        toty   += histy[fil]   * fil;
> -        totu   += histu[fil]   * fil;
> -        totv   += histv[fil]   * fil;
> -        totsat += histsat[fil] * fil;
> +        toty   += (uint64_t)histy[fil]   * fil;
> +        totu   += (uint64_t)histu[fil]   * fil;
> +        totv   += (uint64_t)histv[fil]   * fil;
> +        totsat += (uint64_t)histsat[fil] * fil;
>  
>          accy   += histy[fil];
>          accu   += histu[fil];
> @@ -745,7 +745,7 @@ static int filter_frame(AVFilterLink *link, AVFrame *in)
>      maxhue = histhue[0];
>      medhue = -1;
>      for (fil = 0; fil < 360; fil++) {
> -        tothue += histhue[fil] * fil;
> +        tothue += (uint64_t)histhue[fil] * fil;
>          acchue += histhue[fil];
>  
>          if (medhue == -1 && acchue > s->cfs / 2)

Will apply this patchset tomorrow unless there are objections.

- Andreas
diff mbox series

Patch

diff --git a/libavfilter/vf_signalstats.c b/libavfilter/vf_signalstats.c
index 50c9df4298..78a23bb705 100644
--- a/libavfilter/vf_signalstats.c
+++ b/libavfilter/vf_signalstats.c
@@ -721,10 +721,10 @@  static int filter_frame(AVFilterLink *link, AVFrame *in)
         if (histv[fil])   maxv   = fil;
         if (histsat[fil]) maxsat = fil;
 
-        toty   += histy[fil]   * fil;
-        totu   += histu[fil]   * fil;
-        totv   += histv[fil]   * fil;
-        totsat += histsat[fil] * fil;
+        toty   += (uint64_t)histy[fil]   * fil;
+        totu   += (uint64_t)histu[fil]   * fil;
+        totv   += (uint64_t)histv[fil]   * fil;
+        totsat += (uint64_t)histsat[fil] * fil;
 
         accy   += histy[fil];
         accu   += histu[fil];
@@ -745,7 +745,7 @@  static int filter_frame(AVFilterLink *link, AVFrame *in)
     maxhue = histhue[0];
     medhue = -1;
     for (fil = 0; fil < 360; fil++) {
-        tothue += histhue[fil] * fil;
+        tothue += (uint64_t)histhue[fil] * fil;
         acchue += histhue[fil];
 
         if (medhue == -1 && acchue > s->cfs / 2)