GET_V(st->codec->extradata_size, tmp < (1 << 30));
if (st->codec->extradata_size) {
st->codec->extradata = av_mallocz(st->codec->extradata_size +
- FF_INPUT_BUFFER_PADDING_SIZE);
+ AV_INPUT_BUFFER_PADDING_SIZE);
if (!st->codec->extradata)
return AVERROR(ENOMEM);
avio_read(bc, st->codec->extradata, st->codec->extradata_size);
nut->time_base[chapter_start %
nut->time_base_count],
start, start + chapter_len, NULL);
+ if (!chapter) {
+ av_log(s, AV_LOG_ERROR, "Could not create chapter.\n");
+ return AVERROR(ENOMEM);
+ }
metadata = &chapter->metadata;
} else if (stream_id_plus1) {
st = s->streams[stream_id_plus1 - 1];
GET_V(syncpoint_count, tmp < INT_MAX / 8 && tmp > 0);
syncpoints = av_malloc(sizeof(int64_t) * syncpoint_count);
has_keyframe = av_malloc(sizeof(int8_t) * (syncpoint_count + 1));
- if (!syncpoints || !has_keyframe)
- return AVERROR(ENOMEM);
+ if (!syncpoints || !has_keyframe) {
+ ret = AVERROR(ENOMEM);
+ goto fail;
+ }
for (i = 0; i < syncpoint_count; i++) {
syncpoints[i] = ffio_read_varlen(bc);
if (syncpoints[i] <= 0)
return ret;
}
+static int nut_read_close(AVFormatContext *s)
+{
+ NUTContext *nut = s->priv_data;
+ int i;
+
+ av_freep(&nut->time_base);
+ av_freep(&nut->stream);
+ ff_nut_free_sp(nut);
+ for (i = 1; i < nut->header_count; i++)
+ av_freep(&nut->header[i]);
+
+ return 0;
+}
+
static int nut_read_header(AVFormatContext *s)
{
NUTContext *nut = s->priv_data;
pos = find_startcode(bc, MAIN_STARTCODE, pos) + 1;
if (pos < 0 + 1) {
av_log(s, AV_LOG_ERROR, "No main startcode found.\n");
- return AVERROR_INVALIDDATA;
+ goto fail;
}
} while (decode_main_header(nut) < 0);
pos = find_startcode(bc, STREAM_STARTCODE, pos) + 1;
if (pos < 0 + 1) {
av_log(s, AV_LOG_ERROR, "Not all stream headers found.\n");
- return AVERROR_INVALIDDATA;
+ goto fail;
}
if (decode_stream_header(nut) >= 0)
initialized_stream_count++;
if (startcode == 0) {
av_log(s, AV_LOG_ERROR, "EOF before video frames\n");
- return AVERROR_INVALIDDATA;
+ goto fail;
} else if (startcode == SYNCPOINT_STARTCODE) {
nut->next_startcode = startcode;
break;
ff_metadata_conv_ctx(s, NULL, ff_nut_metadata_conv);
return 0;
+
+fail:
+ nut_read_close(s);
+
+ return AVERROR_INVALIDDATA;
}
static int decode_frame_header(NUTContext *nut, int64_t *pts, int *stream_id,
return 0;
}
-static int nut_read_close(AVFormatContext *s)
-{
- NUTContext *nut = s->priv_data;
- int i;
-
- av_freep(&nut->time_base);
- av_freep(&nut->stream);
- ff_nut_free_sp(nut);
- for (i = 1; i < nut->header_count; i++)
- av_freep(&nut->header[i]);
-
- return 0;
-}
-
AVInputFormat ff_nut_demuxer = {
.name = "nut",
.long_name = NULL_IF_CONFIG_SMALL("NUT"),