[FFmpeg-devel] [PATCH 1/3] aacsbr_fixed: avoid division by zero in sbr_gain_calc

Michael Niedermayer michael at niedermayer.cc
Mon Nov 16 13:46:18 CET 2015

On Fri, Nov 13, 2015 at 11:19:44PM +0100, Andreas Cadhalpun wrote:
> On 13.11.2015 04:21, Michael Niedermayer wrote:
> > On Thu, Nov 12, 2015 at 08:51:28PM +0100, Andreas Cadhalpun wrote:
> >> On 11.11.2015 23:19, Michael Niedermayer wrote:
> >>> On Wed, Nov 11, 2015 at 09:31:18PM +0100, Andreas Cadhalpun wrote:
> >>>> I'm not sure, but it can happen, when q_mapped is very small, which can be
> >>>> caused by noise_facs becoming tiny in sbr_dequant.
> >>>> That's kind of the opposite problem of 'envelope scalefactors overflowing'.
> >>>
> >>> sbr_dequant() does not look like it can set noise_facs to 0
> >>> except by underflow of the exponent range
> >>
> >> That's exactly what happens.
> >>
> >>> that "has" to be invalid as this depends on the implementation 
> >>
> >> So should sbr_dequant error out instead?
> >> If so, what's the minimal value it should accept?
> > 
> > I dont know the valid range, and i doubt the spec lists this
> > so picking what causes a problem (0) would be the easy solution
> > thats what i would suggest in absence of other suggestions
> Well, unfortunately just rejecting 0 in sbr_dequant is no solution,
> because, as you noticed, that only happens via underflow.

a value that has underflowed should be 0, so underflow affecting
anything implies 0 as result and so a check for 0 would cover all
I think i misunderstand somehow

> One could check for exponents smaller than MIN_EXP, but since

exponents must not be smaller than MIN_EXP.
no *_sf function should set such an exponent. code directly writing
exponents has to check for exp < MIN_EXP
that could in principle be done by using a _sf function which allows
such exponents on input and clears it up on output

> the exponent can get smaller during the calculations in sbr_gain_calc,
> that wouldn't necessarily avoid the division by 0.

> Additionally both sbr_dequant and sbr_gain_calc are void functions,
> so can't easily return errors.

iam not sure i understand your concern ?
the resturn type is easy changeable or  flag could be added to the
context indicating an error or a simpler hack could be used to
fix this in the releases with a more complete cleanup in master

but maybe iam missing something why you consider this to be a bad
solution ?

Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Freedom in capitalist society always remains about the same as it was in
ancient Greek republics: Freedom for slave owners. -- Vladimir Lenin
-------------- 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/20151116/0d00c486/attachment.sig>

More information about the ffmpeg-devel mailing list