[FFmpeg-devel] [PATCH] avcodec/apv_dsp: Fix left-shift of negative value

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Thu May 1 00:56:39 EEST 2025


Mark Thompson:
> On 30/04/2025 19:26, Andreas Rheinhardt wrote:
>> Patch attached.
>>
>> - Andreas
> 
> Hmm, the spec does write exactly this but also defines << as arithmetic left shift of a two's complement representation so it works.
> 
> Seems fair, LGTM.
> 
> More generally this line is not robust to extreme values (can integer overflow 32 bits), but the cases which do this are not useful and won't be in real streams (if calculated at full precision they would always be far outside the possible coefficient range from a forward transform, so it takes a crafted encoder to make them).
> 
> Possibly a pre-clip to a calculated range which ensures it doesn't go too far outside the following clip range is the right answer to avoid the overflow?  I will think about this a bit more.
> 

If it does not happen for real files, our usual answer is to use
unsigned types where overflow is defined.

- Andreas



More information about the ffmpeg-devel mailing list