diff mbox series

[FFmpeg-devel,1/3] avformat/utils: Remove redundant check

Message ID 20210324005354.1688230-1-andreas.rheinhardt@gmail.com
State Accepted
Commit 63fcf3da018fd4c884d0780b90141ed22ed86016
Headers show
Series [FFmpeg-devel,1/3] avformat/utils: Remove redundant check | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt March 24, 2021, 12:53 a.m. UTC
This check is outdated because the caller doesn't need to check that
the multiplication overflows when using av_realloc_array() (the code
in question used av_realloc() before that); furthermore, the check
is also a remnant of the time in which our allocation functions
didn't use size_t parameters.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
It would btw make more sense for AVFormatContext.max_streams to be
unsigned.

 libavformat/utils.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Andreas Rheinhardt March 26, 2021, 4:37 a.m. UTC | #1
Andreas Rheinhardt:
> This check is outdated because the caller doesn't need to check that
> the multiplication overflows when using av_realloc_array() (the code
> in question used av_realloc() before that); furthermore, the check
> is also a remnant of the time in which our allocation functions
> didn't use size_t parameters.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
> It would btw make more sense for AVFormatContext.max_streams to be
> unsigned.
> 
>  libavformat/utils.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index 524765aeb4..88f6f18f1f 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -4493,9 +4493,10 @@ AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c)
>      int i;
>      AVStream **streams;
>  
> -    if (s->nb_streams >= FFMIN(s->max_streams, INT_MAX/sizeof(*streams))) {
> -        if (s->max_streams < INT_MAX/sizeof(*streams))
> -            av_log(s, AV_LOG_ERROR, "Number of streams exceeds max_streams parameter (%d), see the documentation if you wish to increase it\n", s->max_streams);
> +    if (s->nb_streams >= s->max_streams) {
> +        av_log(s, AV_LOG_ERROR, "Number of streams exceeds max_streams parameter"
> +               " (%d), see the documentation if you wish to increase it\n",
> +               s->max_streams);
>          return NULL;
>      }
>      streams = av_realloc_array(s->streams, s->nb_streams + 1, sizeof(*streams));
> 
Will apply this patchset tomorrow unless there are objections.

- Andreas
diff mbox series

Patch

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 524765aeb4..88f6f18f1f 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -4493,9 +4493,10 @@  AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c)
     int i;
     AVStream **streams;
 
-    if (s->nb_streams >= FFMIN(s->max_streams, INT_MAX/sizeof(*streams))) {
-        if (s->max_streams < INT_MAX/sizeof(*streams))
-            av_log(s, AV_LOG_ERROR, "Number of streams exceeds max_streams parameter (%d), see the documentation if you wish to increase it\n", s->max_streams);
+    if (s->nb_streams >= s->max_streams) {
+        av_log(s, AV_LOG_ERROR, "Number of streams exceeds max_streams parameter"
+               " (%d), see the documentation if you wish to increase it\n",
+               s->max_streams);
         return NULL;
     }
     streams = av_realloc_array(s->streams, s->nb_streams + 1, sizeof(*streams));