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

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Mon Jan 17 01:05:16 EET 2022


James Almer:
> 
> 
> On 1/16/2022 7:49 PM, Andreas Rheinhardt wrote:
>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at 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


More information about the ffmpeg-devel mailing list