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

Andreas Cadhalpun andreas.cadhalpun at gmail.com
Fri Nov 13 23:19:44 CET 2015

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.
One could check for exponents smaller than MIN_EXP, but since
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.

So the only simple way to avoid the division by zero is adapting
sbr_gain_calc to handle this case gracefully.

Best regards,

More information about the ffmpeg-devel mailing list