diff options
author | Anshul <er.anshul.maheshwari@gmail.com> | 2014-05-14 22:21:58 +0530 |
---|---|---|
committer | Carl Eugen Hoyos <cehoyos@ag.or.at> | 2014-05-21 22:53:49 +0200 |
commit | acafd1814e68d41a3adc508c03f4fd6254826c1d (patch) | |
tree | 317e316ff20245ace155eac2fd7cf1c6d6a3eff4 | |
parent | bb01956d67f9515c0b8d77ab7800cc3bda010033 (diff) | |
download | ffmpeg-acafd1814e68d41a3adc508c03f4fd6254826c1d.tar.gz |
ffprobe: fix crash happening because of new streams occuring
Fix trac ticket #3603.
Signed-off-by: Stefano Sabatini <stefasab@gmail.com>
(cherry picked from commit 73a60633143b7c51333a0772b45a47282ac445b6)
-rw-r--r-- | ffprobe.c | 22 |
1 files changed, 19 insertions, 3 deletions
@@ -191,6 +191,7 @@ static const char unit_hertz_str[] = "Hz" ; static const char unit_byte_str[] = "byte" ; static const char unit_bit_per_second_str[] = "bit/s"; +static int nb_streams; static uint64_t *nb_streams_packets; static uint64_t *nb_streams_frames; static int *selected_streams; @@ -1632,6 +1633,14 @@ static void writer_register_all(void) #define print_section_header(s) writer_print_section_header(w, s) #define print_section_footer(s) writer_print_section_footer(w, s) +#define REALLOCZ_ARRAY_STREAM(ptr, cur_n, new_n) \ +{ \ + ret = av_reallocp_array(&(ptr), (new_n), sizeof(*(ptr))); \ + if (ret < 0) \ + goto end; \ + memset( (ptr) + (cur_n), 0, ((new_n) - (cur_n)) * sizeof(*(ptr)) ); \ +} + static inline int show_tags(WriterContext *w, AVDictionary *tags, int section_id) { AVDictionaryEntry *tag = NULL; @@ -1893,6 +1902,12 @@ static int read_interval_packets(WriterContext *w, AVFormatContext *fmt_ctx, goto end; } while (!av_read_frame(fmt_ctx, &pkt)) { + if (fmt_ctx->nb_streams > nb_streams) { + REALLOCZ_ARRAY_STREAM(nb_streams_frames, nb_streams, fmt_ctx->nb_streams); + REALLOCZ_ARRAY_STREAM(nb_streams_packets, nb_streams, fmt_ctx->nb_streams); + REALLOCZ_ARRAY_STREAM(selected_streams, nb_streams, fmt_ctx->nb_streams); + nb_streams = fmt_ctx->nb_streams; + } if (selected_streams[pkt.stream_index]) { AVRational tb = fmt_ctx->streams[pkt.stream_index]->time_base; @@ -2367,9 +2382,10 @@ static int probe_file(WriterContext *wctx, const char *filename) #define CHECK_END if (ret < 0) goto end - nb_streams_frames = av_calloc(fmt_ctx->nb_streams, sizeof(*nb_streams_frames)); - nb_streams_packets = av_calloc(fmt_ctx->nb_streams, sizeof(*nb_streams_packets)); - selected_streams = av_calloc(fmt_ctx->nb_streams, sizeof(*selected_streams)); + nb_streams = fmt_ctx->nb_streams; + REALLOCZ_ARRAY_STREAM(nb_streams_frames,0,fmt_ctx->nb_streams); + REALLOCZ_ARRAY_STREAM(nb_streams_packets,0,fmt_ctx->nb_streams); + REALLOCZ_ARRAY_STREAM(selected_streams,0,fmt_ctx->nb_streams); for (i = 0; i < fmt_ctx->nb_streams; i++) { if (stream_specifier) { |