diff mbox series

[FFmpeg-devel,1/3] avcodec/lpc: check for zero err in normalization in compute_lpc_coefs()

Message ID 20210601073315.9104-1-michael@niedermayer.cc
State Accepted
Headers show
Series [FFmpeg-devel,1/3] avcodec/lpc: check for zero err in normalization in compute_lpc_coefs() | expand

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

Michael Niedermayer June 1, 2021, 7:33 a.m. UTC
Fixes: floating point division by 0
Fixes: Ticket8213

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/lpc.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Anton Khirnov June 5, 2021, 1:44 p.m. UTC | #1
Quoting Michael Niedermayer (2021-06-01 09:33:13)
> Fixes: floating point division by 0
> Fixes: Ticket8213
> 
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/lpc.h | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/lpc.h b/libavcodec/lpc.h
> index 52170fd623..c99e568794 100644
> --- a/libavcodec/lpc.h
> +++ b/libavcodec/lpc.h
> @@ -186,7 +186,8 @@ static inline int AAC_RENAME(compute_lpc_coefs)(const LPC_TYPE *autoc, int max_o
>              for(j=0; j<i; j++)
>                  r -= lpc_last[j] * autoc[i-j-1];
>  
> -            r /= err;
> +            if (r || err)

Why check for non-zero r?
Michael Niedermayer June 5, 2021, 2:14 p.m. UTC | #2
On Sat, Jun 05, 2021 at 03:44:49PM +0200, Anton Khirnov wrote:
> Quoting Michael Niedermayer (2021-06-01 09:33:13)
> > Fixes: floating point division by 0
> > Fixes: Ticket8213
> > 
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >  libavcodec/lpc.h | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/libavcodec/lpc.h b/libavcodec/lpc.h
> > index 52170fd623..c99e568794 100644
> > --- a/libavcodec/lpc.h
> > +++ b/libavcodec/lpc.h
> > @@ -186,7 +186,8 @@ static inline int AAC_RENAME(compute_lpc_coefs)(const LPC_TYPE *autoc, int max_o
> >              for(j=0; j<i; j++)
> >                  r -= lpc_last[j] * autoc[i-j-1];
> >  
> > -            r /= err;
> > +            if (r || err)
> 
> Why check for non-zero r?

The idea was to make it clear what the case was that this checked for
i can drop the r check if you prefer ?

[...]
Anton Khirnov June 5, 2021, 4:12 p.m. UTC | #3
Quoting Michael Niedermayer (2021-06-05 16:14:24)
> On Sat, Jun 05, 2021 at 03:44:49PM +0200, Anton Khirnov wrote:
> > Quoting Michael Niedermayer (2021-06-01 09:33:13)
> > > Fixes: floating point division by 0
> > > Fixes: Ticket8213
> > > 
> > > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > > ---
> > >  libavcodec/lpc.h | 3 ++-
> > >  1 file changed, 2 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/libavcodec/lpc.h b/libavcodec/lpc.h
> > > index 52170fd623..c99e568794 100644
> > > --- a/libavcodec/lpc.h
> > > +++ b/libavcodec/lpc.h
> > > @@ -186,7 +186,8 @@ static inline int AAC_RENAME(compute_lpc_coefs)(const LPC_TYPE *autoc, int max_o
> > >              for(j=0; j<i; j++)
> > >                  r -= lpc_last[j] * autoc[i-j-1];
> > >  
> > > -            r /= err;
> > > +            if (r || err)
> > 
> > Why check for non-zero r?
> 
> The idea was to make it clear what the case was that this checked for
> i can drop the r check if you prefer ?

So something guarantees that when r is non-zero then err is also
non-zero? It's not obvious to me, but I don't understand that code.
Maybe a comment would be enough.
Michael Niedermayer July 2, 2021, 9:14 p.m. UTC | #4
On Sat, Jun 05, 2021 at 06:12:47PM +0200, Anton Khirnov wrote:
> Quoting Michael Niedermayer (2021-06-05 16:14:24)
> > On Sat, Jun 05, 2021 at 03:44:49PM +0200, Anton Khirnov wrote:
> > > Quoting Michael Niedermayer (2021-06-01 09:33:13)
> > > > Fixes: floating point division by 0
> > > > Fixes: Ticket8213
> > > > 
> > > > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > > > ---
> > > >  libavcodec/lpc.h | 3 ++-
> > > >  1 file changed, 2 insertions(+), 1 deletion(-)
> > > > 
> > > > diff --git a/libavcodec/lpc.h b/libavcodec/lpc.h
> > > > index 52170fd623..c99e568794 100644
> > > > --- a/libavcodec/lpc.h
> > > > +++ b/libavcodec/lpc.h
> > > > @@ -186,7 +186,8 @@ static inline int AAC_RENAME(compute_lpc_coefs)(const LPC_TYPE *autoc, int max_o
> > > >              for(j=0; j<i; j++)
> > > >                  r -= lpc_last[j] * autoc[i-j-1];
> > > >  
> > > > -            r /= err;
> > > > +            if (r || err)
> > > 
> > > Why check for non-zero r?
> > 
> > The idea was to make it clear what the case was that this checked for
> > i can drop the r check if you prefer ?
> 
> So something guarantees that when r is non-zero then err is also
> non-zero? It's not obvious to me, but I don't understand that code.
> Maybe a comment would be enough.

With rounding any combination can likely occur so i will just check for
err. I should have done this in the initial patch, what i did in it
was insufficient.

thx

[...]
diff mbox series

Patch

diff --git a/libavcodec/lpc.h b/libavcodec/lpc.h
index 52170fd623..c99e568794 100644
--- a/libavcodec/lpc.h
+++ b/libavcodec/lpc.h
@@ -186,7 +186,8 @@  static inline int AAC_RENAME(compute_lpc_coefs)(const LPC_TYPE *autoc, int max_o
             for(j=0; j<i; j++)
                 r -= lpc_last[j] * autoc[i-j-1];
 
-            r /= err;
+            if (r || err)
+                r /= err;
             err *= FIXR(1.0) - (r * r);
         }