diff mbox series

[FFmpeg-devel,01/25] avformat/matroskaenc: Fix potential overflow

Message ID AM7PR03MB66609FAEE5128E3BA3F57C0F8F569@AM7PR03MB6660.eurprd03.prod.outlook.com
State Accepted
Commit ca168635494276bb7f2f686de07747e7f493e30c
Headers show
Series [FFmpeg-devel,01/25] avformat/matroskaenc: Fix potential overflow | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_aarch64_jetson success Make finished
andriy/make_fate_aarch64_jetson success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Andreas Rheinhardt Jan. 16, 2022, 10:49 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavformat/matroskaenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

James Almer Jan. 16, 2022, 10:51 p.m. UTC | #1
On 1/16/2022 7:49 PM, Andreas Rheinhardt wrote:
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>   libavformat/matroskaenc.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
> index 41b2df7dbf..1dde12a7d9 100644
> --- a/libavformat/matroskaenc.c
> +++ b/libavformat/matroskaenc.c
> @@ -286,7 +286,7 @@ static void put_ebml_uint(AVIOContext *pb, uint32_t elementid, uint64_t val)
>   static void put_ebml_sint(AVIOContext *pb, uint32_t elementid, int64_t val)
>   {
>       int i, bytes = 1;
> -    uint64_t tmp = 2*(val < 0 ? val^-1 : val);
> +    uint64_t tmp = 2 * (uint64_t)(val < 0 ? val^-1 : val);

nit: 2ULL is shorter.

>   
>       while (tmp >>= 8)
>           bytes++;
Andreas Rheinhardt Jan. 16, 2022, 11:05 p.m. UTC | #2
James Almer:
> 
> 
> On 1/16/2022 7:49 PM, Andreas Rheinhardt wrote:
>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
>> ---
>>   libavformat/matroskaenc.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
>> index 41b2df7dbf..1dde12a7d9 100644
>> --- a/libavformat/matroskaenc.c
>> +++ b/libavformat/matroskaenc.c
>> @@ -286,7 +286,7 @@ static void put_ebml_uint(AVIOContext *pb,
>> uint32_t elementid, uint64_t val)
>>   static void put_ebml_sint(AVIOContext *pb, uint32_t elementid,
>> int64_t val)
>>   {
>>       int i, bytes = 1;
>> -    uint64_t tmp = 2*(val < 0 ? val^-1 : val);
>> +    uint64_t tmp = 2 * (uint64_t)(val < 0 ? val^-1 : val);
> 
> nit: 2ULL is shorter.
> 

This is correct, but the above is more natural; after all, it is (val <
0 ? val^-1 : val) that is reinterpreted as uint64_t.

- Andreas
Andreas Rheinhardt Jan. 18, 2022, 11:17 a.m. UTC | #3
Andreas Rheinhardt:
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavformat/matroskaenc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
> index 41b2df7dbf..1dde12a7d9 100644
> --- a/libavformat/matroskaenc.c
> +++ b/libavformat/matroskaenc.c
> @@ -286,7 +286,7 @@ static void put_ebml_uint(AVIOContext *pb, uint32_t elementid, uint64_t val)
>  static void put_ebml_sint(AVIOContext *pb, uint32_t elementid, int64_t val)
>  {
>      int i, bytes = 1;
> -    uint64_t tmp = 2*(val < 0 ? val^-1 : val);
> +    uint64_t tmp = 2 * (uint64_t)(val < 0 ? val^-1 : val);
>  
>      while (tmp >>= 8)
>          bytes++;
> 

Will apply this patchset tomorrow unless there are objections.

- Andreas
diff mbox series

Patch

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 41b2df7dbf..1dde12a7d9 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -286,7 +286,7 @@  static void put_ebml_uint(AVIOContext *pb, uint32_t elementid, uint64_t val)
 static void put_ebml_sint(AVIOContext *pb, uint32_t elementid, int64_t val)
 {
     int i, bytes = 1;
-    uint64_t tmp = 2*(val < 0 ? val^-1 : val);
+    uint64_t tmp = 2 * (uint64_t)(val < 0 ? val^-1 : val);
 
     while (tmp >>= 8)
         bytes++;