Skip to content

Commit

Permalink
avformat/nutdec: Add check for avformat_new_stream
Browse files Browse the repository at this point in the history
Check for failure of avformat_new_stream() and propagate
the error code.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
  • Loading branch information
JiangJias authored and jamrial committed May 28, 2023
1 parent e14e757 commit 08f0a18
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions libavformat/nutdec.c
Expand Up @@ -358,8 +358,12 @@ static int decode_main_header(NUTContext *nut)
ret = AVERROR(ENOMEM);
goto fail;
}
for (i = 0; i < stream_count; i++)
avformat_new_stream(s, NULL);
for (i = 0; i < stream_count; i++) {
if (!avformat_new_stream(s, NULL)) {
ret = AVERROR(ENOMEM);
goto fail;
}
}

return 0;
fail:
Expand Down Expand Up @@ -805,19 +809,23 @@ static int nut_read_header(AVFormatContext *s)
NUTContext *nut = s->priv_data;
AVIOContext *bc = s->pb;
int64_t pos;
int initialized_stream_count;
int initialized_stream_count, ret;

nut->avf = s;

/* main header */
pos = 0;
ret = 0;
do {
if (ret == AVERROR(ENOMEM))
return ret;

pos = find_startcode(bc, MAIN_STARTCODE, pos) + 1;
if (pos < 0 + 1) {
av_log(s, AV_LOG_ERROR, "No main startcode found.\n");
goto fail;
}
} while (decode_main_header(nut) < 0);
} while ((ret = decode_main_header(nut)) < 0);

/* stream headers */
pos = 0;
Expand Down

0 comments on commit 08f0a18

Please sign in to comment.