X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Fconcat.c;h=278afd997ddd6d32919226260aa7129c867a8942;hb=a04ad248a05e7b613abe09b3bb067f555108d794;hp=19c83c309acff167459902552e842da2707b4a10;hpb=de33b3e457a656230fc6d544a1889218d77a5b3c;p=ffmpeg diff --git a/libavformat/concat.c b/libavformat/concat.c index 19c83c309ac..278afd997dd 100644 --- a/libavformat/concat.c +++ b/libavformat/concat.c @@ -38,6 +38,7 @@ struct concat_data { struct concat_nodes *nodes; ///< list of nodes to concat size_t length; ///< number of cat'ed nodes size_t current; ///< index of currently read node + uint64_t total_size; }; static av_cold int concat_close(URLContext *h) @@ -48,7 +49,7 @@ static av_cold int concat_close(URLContext *h) struct concat_nodes *nodes = data->nodes; for (i = 0; i != data->length; i++) - err |= ffurl_close(nodes[i].uc); + err |= ffurl_closep(&nodes[i].uc); av_freep(&data->nodes); @@ -59,7 +60,7 @@ static av_cold int concat_open(URLContext *h, const char *uri, int flags) { char *node_uri = NULL; int err = 0; - int64_t size; + int64_t size, total_size = 0; size_t len, i; URLContext *uc; struct concat_data *data = h->priv_data; @@ -72,15 +73,11 @@ static av_cold int concat_open(URLContext *h, const char *uri, int flags) for (i = 0, len = 1; uri[i]; i++) { if (uri[i] == *AV_CAT_SEPARATOR) { - /* integer overflow */ - if (++len == UINT_MAX / sizeof(*nodes)) { - av_freep(&h->priv_data); - return AVERROR(ENAMETOOLONG); - } + len++; } } - if (!(nodes = av_realloc(NULL, sizeof(*nodes) * len))) + if (!(nodes = av_realloc_array(NULL, len, sizeof(*nodes)))) return AVERROR(ENOMEM); else data->nodes = nodes; @@ -112,6 +109,7 @@ static av_cold int concat_open(URLContext *h, const char *uri, int flags) /* assembling */ nodes[i].uc = uc; nodes[i].size = size; + total_size += size; } av_free(node_uri); data->length = i; @@ -123,6 +121,7 @@ static av_cold int concat_open(URLContext *h, const char *uri, int flags) err = AVERROR(ENOMEM); } else data->nodes = nodes; + data->total_size = total_size; return err; } @@ -158,6 +157,8 @@ static int64_t concat_seek(URLContext *h, int64_t pos, int whence) struct concat_nodes *nodes = data->nodes; size_t i; + if ((whence & AVSEEK_SIZE)) + return data->total_size; switch (whence) { case SEEK_END: for (i = data->length - 1; i && pos < -nodes[i].size; i--)