[FFmpeg-devel] [PATCH 4/4] softfloat: return one when the argument of av_sqrt_sf is negative

Michael Niedermayer michael at niedermayer.cc
Sun Nov 8 01:02:37 CET 2015


On Sun, Nov 08, 2015 at 12:09:02AM +0100, Andreas Cadhalpun wrote:
> Mathematically this is bogus, but it is much better than the previous
> behaviour: returning a random value from an out of bounds read.
> 
> Returning zero will just lead to division by zero problems.
> 
> This fixes av_assert2 failures in the aac_fixed decoder.
> 
> Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun at googlemail.com>
> ---
>  libavutil/softfloat.h | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/libavutil/softfloat.h b/libavutil/softfloat.h
> index fefde8c..0a2074a 100644
> --- a/libavutil/softfloat.h
> +++ b/libavutil/softfloat.h
> @@ -170,6 +170,8 @@ static av_always_inline SoftFloat av_sqrt_sf(SoftFloat val)
>  
>      if (val.mant == 0)
>          val.exp = 0;
> +    else if (val.mant < 0)
> +        val = FLOAT_1;

this is IMHO not ok
sqrt(-1) has 3 sane possible outcomes
1. the complex number i
2. NaN
3. abort()

like division by 0 sqare roots of negative numbers in a context of
real values are a bug, there is likely something wrong in the code
that is calling sqrt with a negative number and simply returning 1
silently would make it hard to find and debug such bugs

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Concerning the gods, I have no means of knowing whether they exist or not
or of what sort they may be, because of the obscurity of the subject, and
the brevity of human life -- Protagoras
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20151108/da395ad9/attachment.sig>


More information about the ffmpeg-devel mailing list