[FFmpeg-cvslog] ffprobe: fix crash happening because of new streams occuring
Anshul
git at videolan.org
Wed May 21 23:09:59 CEST 2014
ffmpeg | branch: release/2.1 | Anshul <er.anshul.maheshwari at gmail.com> | Wed May 14 22:39:58 2014 +0530| [83f58778cb6a08c16cf1589e91a84785162bcd64] | committer: Carl Eugen Hoyos
ffprobe: fix crash happening because of new streams occuring
Fix trac ticket #3603.
Signed-off-by: Stefano Sabatini <stefasab at gmail.com>
(cherry picked from commit 73a60633143b7c51333a0772b45a47282ac445b6)
Conflicts:
ffprobe.c
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=83f58778cb6a08c16cf1589e91a84785162bcd64
---
ffprobe.c | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
diff --git a/ffprobe.c b/ffprobe.c
index 7f9c737..ba11060 100644
--- a/ffprobe.c
+++ b/ffprobe.c
@@ -183,6 +183,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;
@@ -1456,6 +1457,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 void show_tags(WriterContext *wctx, AVDictionary *tags, int section_id)
{
AVDictionaryEntry *tag = NULL;
@@ -1674,6 +1683,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;
@@ -2117,9 +2132,10 @@ static int probe_file(WriterContext *wctx, const char *filename)
if (ret < 0)
return ret;
- 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) {
More information about the ffmpeg-cvslog
mailing list