diff mbox series

[FFmpeg-devel] avcodec/hevc_ps: Fix UB 1 << 31

Message ID GV1P250MB0737FA4BED5AD60F3C78C8328FFD2@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM
State New
Headers show
Series [FFmpeg-devel] avcodec/hevc_ps: Fix UB 1 << 31 | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt June 1, 2024, 1:13 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/hevc_ps.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Tomas Härdin June 1, 2024, 3:01 p.m. UTC | #1
lör 2024-06-01 klockan 15:13 +0200 skrev Andreas Rheinhardt:
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavcodec/hevc_ps.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
> index 7b486ce0af..1a459ad054 100644
> --- a/libavcodec/hevc_ps.c
> +++ b/libavcodec/hevc_ps.c
> @@ -200,7 +200,7 @@ int ff_hevc_decode_short_term_rps(GetBitContext
> *gb, AVCodecContext *avctx,
>          }
>  
>          for (unsigned i = 0; i < FF_ARRAY_ELEMS(used); i++)
> -            rps->used |= used[i] * (1 << i);
> +            rps->used |= used[i] * (1U << i);

Why not just (uint32_t)used[i] << i?

/Tomas
Andreas Rheinhardt June 1, 2024, 3:10 p.m. UTC | #2
Tomas Härdin:
> lör 2024-06-01 klockan 15:13 +0200 skrev Andreas Rheinhardt:
>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
>> ---
>>  libavcodec/hevc_ps.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
>> index 7b486ce0af..1a459ad054 100644
>> --- a/libavcodec/hevc_ps.c
>> +++ b/libavcodec/hevc_ps.c
>> @@ -200,7 +200,7 @@ int ff_hevc_decode_short_term_rps(GetBitContext
>> *gb, AVCodecContext *avctx,
>>          }
>>  
>>          for (unsigned i = 0; i < FF_ARRAY_ELEMS(used); i++)
>> -            rps->used |= used[i] * (1 << i);
>> +            rps->used |= used[i] * (1U << i);
> 
> Why not just (uint32_t)used[i] << i?
> 

Pondered doing that, but didn't want to change the code too much. But
I'll do it now given that you desired it.

- Andreas
diff mbox series

Patch

diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
index 7b486ce0af..1a459ad054 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -200,7 +200,7 @@  int ff_hevc_decode_short_term_rps(GetBitContext *gb, AVCodecContext *avctx,
         }
 
         for (unsigned i = 0; i < FF_ARRAY_ELEMS(used); i++)
-            rps->used |= used[i] * (1 << i);
+            rps->used |= used[i] * (1U << i);
     } else {
         unsigned int nb_positive_pics;