diff mbox series

[FFmpeg-devel] avfilter/af_astats: fix possible crash because of undefined float to integer rounding

Message ID 20210116085659.17641-1-cus@passwd.hu
State Accepted
Commit c8e1e56509c3f176803cdf40b4019263125fa43f
Headers show
Series [FFmpeg-devel] avfilter/af_astats: fix possible crash because of undefined float to integer rounding
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Marton Balint Jan. 16, 2021, 8:56 a.m. UTC
Fixes ticket #9049.

Signed-off-by: Marton Balint <cus@passwd.hu>
---
 libavfilter/af_astats.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Marton Balint Jan. 18, 2021, 8:54 p.m. UTC | #1
On Sat, 16 Jan 2021, Marton Balint wrote:

> Fixes ticket #9049.
>
> Signed-off-by: Marton Balint <cus@passwd.hu>
> ---
> libavfilter/af_astats.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/libavfilter/af_astats.c b/libavfilter/af_astats.c
> index ebaae29f44..f50cbe199c 100644
> --- a/libavfilter/af_astats.c
> +++ b/libavfilter/af_astats.c
> @@ -329,11 +329,11 @@ static inline void update_stat(AudioStatsContext *s, ChannelStats *p, double d,
>
>     drop = p->win_samples[p->win_pos];
>     p->win_samples[p->win_pos] = nd;
> -    index = av_clip(FFABS(av_clipd(nd, -1.0, 1.0)) * HISTOGRAM_MAX, 0, HISTOGRAM_MAX);
> +    index = av_clip(lrint(av_clipd(FFABS(nd), 0.0, 1.0) * HISTOGRAM_MAX), 0, HISTOGRAM_MAX);
>     p->max_index = FFMAX(p->max_index, index);
>     p->histogram[index]++;
>     if (!isnan(p->noise_floor))
> -        p->histogram[av_clip(FFABS(drop) * HISTOGRAM_MAX, 0, HISTOGRAM_MAX)]--;
> +        p->histogram[av_clip(lrint(av_clipd(FFABS(drop), 0.0, 1.0) * HISTOGRAM_MAX), 0, HISTOGRAM_MAX)]--;
>     p->win_pos++;
>
>     while (p->histogram[p->max_index] == 0)

Will apply soon.

Regards,
Marton
diff mbox series

Patch

diff --git a/libavfilter/af_astats.c b/libavfilter/af_astats.c
index ebaae29f44..f50cbe199c 100644
--- a/libavfilter/af_astats.c
+++ b/libavfilter/af_astats.c
@@ -329,11 +329,11 @@  static inline void update_stat(AudioStatsContext *s, ChannelStats *p, double d,
 
     drop = p->win_samples[p->win_pos];
     p->win_samples[p->win_pos] = nd;
-    index = av_clip(FFABS(av_clipd(nd, -1.0, 1.0)) * HISTOGRAM_MAX, 0, HISTOGRAM_MAX);
+    index = av_clip(lrint(av_clipd(FFABS(nd), 0.0, 1.0) * HISTOGRAM_MAX), 0, HISTOGRAM_MAX);
     p->max_index = FFMAX(p->max_index, index);
     p->histogram[index]++;
     if (!isnan(p->noise_floor))
-        p->histogram[av_clip(FFABS(drop) * HISTOGRAM_MAX, 0, HISTOGRAM_MAX)]--;
+        p->histogram[av_clip(lrint(av_clipd(FFABS(drop), 0.0, 1.0) * HISTOGRAM_MAX), 0, HISTOGRAM_MAX)]--;
     p->win_pos++;
 
     while (p->histogram[p->max_index] == 0)