mirror of
https://mirror.skon.top/https://github.com/FFmpeg/FFmpeg
synced 2026-04-23 02:11:14 +08:00
swscale/ops: avoid UB in ff_sws_pixel_expand()
Restructure the loop slightly to avoid UB in the first loop iteration if src is 4 bytes, which otherwise computes (0 << 32) | 1. Instead, make 1 the default base case and only shift+add if src < dst. Add an explicit check to preserve the behavior of returnin 0 if src > dst.
This commit is contained in:
@@ -31,9 +31,11 @@ static inline AVRational ff_sws_pixel_expand(SwsPixelType from, SwsPixelType to)
|
||||
{
|
||||
const int src = ff_sws_pixel_type_size(from);
|
||||
const int dst = ff_sws_pixel_type_size(to);
|
||||
int scale = 0;
|
||||
for (int i = 0; i < dst / src; i++)
|
||||
scale = scale << src * 8 | 1;
|
||||
if (src > dst)
|
||||
return Q(0);
|
||||
int scale = 1;
|
||||
for (int i = 1; i < dst / src; i++)
|
||||
scale = (scale << (src * 8)) | 1;
|
||||
return Q(scale);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user