diff mbox series

[FFmpeg-devel] fftools/ffmpeg_mux_init: Return error upon error

Message ID AS8P250MB0744A71FB0510D86914122028FC62@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM
State New
Headers show
Series [FFmpeg-devel] fftools/ffmpeg_mux_init: Return error upon error | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt June 10, 2024, 1:24 p.m. UTC
Currently it may return an uninitialized value.
Introduced in 840f2bc18eddd72fa886aec30efc82991b920c45.
Fixes Coverity issue #1603565.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 fftools/ffmpeg_mux_init.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Anton Khirnov June 11, 2024, 5:35 a.m. UTC | #1
Quoting Andreas Rheinhardt (2024-06-10 15:24:49)
> Currently it may return an uninitialized value.
> Introduced in 840f2bc18eddd72fa886aec30efc82991b920c45.
> Fixes Coverity issue #1603565.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  fftools/ffmpeg_mux_init.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
> index b1cb6cf7bd..1953655135 100644
> --- a/fftools/ffmpeg_mux_init.c
> +++ b/fftools/ffmpeg_mux_init.c
> @@ -3022,10 +3022,13 @@ static int parse_forced_key_frames(void *log, KeyframeForceCtx *kf,
>              unsigned int    nb_ch = mux->fc->nb_chapters;
>              int j;
>  
> -            if (nb_ch > INT_MAX - size ||
> -                !(pts = av_realloc_f(pts, size += nb_ch - 1,
> -                                     sizeof(*pts))))
> +            if (nb_ch > INT_MAX - size) {
> +                ret = AVERROR(ERANGE);
>                  goto fail;
> +            }
> +            pts = av_realloc_f(pts, size += nb_ch - 1, sizeof(*pts));
> +            if (!pts)
> +                return AVERROR(ENOMEM);

Looks good.

Would look even better with the size increment outside of the
av_realloc_f() call.
Andreas Rheinhardt June 11, 2024, 6:38 a.m. UTC | #2
Anton Khirnov:
> Quoting Andreas Rheinhardt (2024-06-10 15:24:49)
>> Currently it may return an uninitialized value.
>> Introduced in 840f2bc18eddd72fa886aec30efc82991b920c45.
>> Fixes Coverity issue #1603565.
>>
>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
>> ---
>>  fftools/ffmpeg_mux_init.c | 9 ++++++---
>>  1 file changed, 6 insertions(+), 3 deletions(-)
>>
>> diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
>> index b1cb6cf7bd..1953655135 100644
>> --- a/fftools/ffmpeg_mux_init.c
>> +++ b/fftools/ffmpeg_mux_init.c
>> @@ -3022,10 +3022,13 @@ static int parse_forced_key_frames(void *log, KeyframeForceCtx *kf,
>>              unsigned int    nb_ch = mux->fc->nb_chapters;
>>              int j;
>>  
>> -            if (nb_ch > INT_MAX - size ||
>> -                !(pts = av_realloc_f(pts, size += nb_ch - 1,
>> -                                     sizeof(*pts))))
>> +            if (nb_ch > INT_MAX - size) {
>> +                ret = AVERROR(ERANGE);
>>                  goto fail;
>> +            }
>> +            pts = av_realloc_f(pts, size += nb_ch - 1, sizeof(*pts));
>> +            if (!pts)
>> +                return AVERROR(ENOMEM);
> 
> Looks good.
> 
> Would look even better with the size increment outside of the
> av_realloc_f() call.
> 

Apply with that change.

- Andreas
Andreas Rheinhardt June 11, 2024, 6:40 a.m. UTC | #3
Andreas Rheinhardt:
> Anton Khirnov:
>> Quoting Andreas Rheinhardt (2024-06-10 15:24:49)
>>> Currently it may return an uninitialized value.
>>> Introduced in 840f2bc18eddd72fa886aec30efc82991b920c45.
>>> Fixes Coverity issue #1603565.
>>>
>>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
>>> ---
>>>  fftools/ffmpeg_mux_init.c | 9 ++++++---
>>>  1 file changed, 6 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
>>> index b1cb6cf7bd..1953655135 100644
>>> --- a/fftools/ffmpeg_mux_init.c
>>> +++ b/fftools/ffmpeg_mux_init.c
>>> @@ -3022,10 +3022,13 @@ static int parse_forced_key_frames(void *log, KeyframeForceCtx *kf,
>>>              unsigned int    nb_ch = mux->fc->nb_chapters;
>>>              int j;
>>>  
>>> -            if (nb_ch > INT_MAX - size ||
>>> -                !(pts = av_realloc_f(pts, size += nb_ch - 1,
>>> -                                     sizeof(*pts))))
>>> +            if (nb_ch > INT_MAX - size) {
>>> +                ret = AVERROR(ERANGE);
>>>                  goto fail;
>>> +            }
>>> +            pts = av_realloc_f(pts, size += nb_ch - 1, sizeof(*pts));
>>> +            if (!pts)
>>> +                return AVERROR(ENOMEM);
>>
>> Looks good.
>>
>> Would look even better with the size increment outside of the
>> av_realloc_f() call.
>>
> 
> Apply with that change.

s/Apply/Applied/

> 
> - Andreas
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox series

Patch

diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index b1cb6cf7bd..1953655135 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -3022,10 +3022,13 @@  static int parse_forced_key_frames(void *log, KeyframeForceCtx *kf,
             unsigned int    nb_ch = mux->fc->nb_chapters;
             int j;
 
-            if (nb_ch > INT_MAX - size ||
-                !(pts = av_realloc_f(pts, size += nb_ch - 1,
-                                     sizeof(*pts))))
+            if (nb_ch > INT_MAX - size) {
+                ret = AVERROR(ERANGE);
                 goto fail;
+            }
+            pts = av_realloc_f(pts, size += nb_ch - 1, sizeof(*pts));
+            if (!pts)
+                return AVERROR(ENOMEM);
 
             if (p[8]) {
                 ret = av_parse_time(&t, p + 8, 1);