X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Favidec.c;h=6112af42e1d69a29fe937e641a5675992699f330;hb=7b2dba1c50c92c76f147727be7c27872252e29f6;hp=158c6a65514a90d10bb79ef56de10ff5222d66f8;hpb=022f8d27dd0a61bfaae729d53d133b17418ea16b;p=ffmpeg diff --git a/libavformat/avidec.c b/libavformat/avidec.c index 158c6a65514..6112af42e1d 100644 --- a/libavformat/avidec.c +++ b/libavformat/avidec.c @@ -26,6 +26,7 @@ #include "libavutil/dict.h" #include "libavutil/avstring.h" #include "avformat.h" +#include "internal.h" #include "avi.h" #include "dv.h" #include "riff.h" @@ -99,6 +100,11 @@ static const char avi_headers[][8] = { { 0 } }; +static const AVMetadataConv avi_metadata_conv[] = { + { "strn", "title" }, + { 0 }, +}; + static int avi_load_index(AVFormatContext *s); static int guess_ni_flag(AVFormatContext *s); @@ -287,15 +293,6 @@ static int avi_read_tag(AVFormatContext *s, AVStream *st, uint32_t tag, uint32_t AV_DICT_DONT_STRDUP_VAL); } -static void avi_read_info(AVFormatContext *s, uint64_t end) -{ - while (avio_tell(s->pb) < end) { - uint32_t tag = avio_rl32(s->pb); - uint32_t size = avio_rl32(s->pb); - avi_read_tag(s, NULL, tag, size); - } -} - static const char months[12][4] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; @@ -390,6 +387,11 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) tag = avio_rl32(pb); size = avio_rl32(pb); + if(size > avi->fsize){ + av_log(s, AV_LOG_ERROR, "chunk size is too big during header parsing\n"); + goto fail; + } + print_tag("tag", tag, size); switch(tag) { @@ -408,7 +410,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) goto end_of_header; } else if (tag1 == MKTAG('I', 'N', 'F', 'O')) - avi_read_info(s, list_end); + ff_read_riff_info(s, size - 4); else if (tag1 == MKTAG('n', 'c', 'd', 't')) avi_read_nikon(s, list_end); @@ -534,7 +536,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) ast->scale = 1; } } - av_set_pts_info(st, 64, ast->scale, ast->rate); + avpriv_set_pts_info(st, 64, ast->scale, ast->rate); ast->cum_len=avio_rl32(pb); /* start */ st->nb_frames = avio_rl32(pb); @@ -621,12 +623,8 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) pal_size = FFMIN(pal_size, st->codec->extradata_size); pal_src = st->codec->extradata + st->codec->extradata_size - pal_size; -#if HAVE_BIGENDIAN for (i = 0; i < pal_size/4; i++) - ast->pal[i] = AV_RL32(pal_src+4*i); -#else - memcpy(ast->pal, pal_src, pal_size); -#endif + ast->pal[i] = 0xFF<<24 | AV_RL32(pal_src+4*i); ast->has_pal = 1; } @@ -778,7 +776,8 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) clean_index(s); } - ff_metadata_conv_ctx(s, NULL, ff_avi_metadata_conv); + ff_metadata_conv_ctx(s, NULL, avi_metadata_conv); + ff_metadata_conv_ctx(s, NULL, ff_riff_info_conv); return 0; } @@ -820,7 +819,7 @@ static int read_gab2_sub(AVStream *st, AVPacket *pkt) { *st->codec = *ast->sub_ctx->streams[0]->codec; ast->sub_ctx->streams[0]->codec->extradata = NULL; time_base = ast->sub_ctx->streams[0]->time_base; - av_set_pts_info(st, 64, time_base.num, time_base.den); + avpriv_set_pts_info(st, 64, time_base.num, time_base.den); } ast->sub_buffer = pkt->data; memset(pkt, 0, sizeof(*pkt)); @@ -968,7 +967,7 @@ start_sync: avio_rl16(pb); //flags for (; k <= last; k++) - ast->pal[k] = avio_rb32(pb)>>8;// b + (g << 8) + (r << 16); + ast->pal[k] = 0xFF<<24 | avio_rb32(pb)>>8;// b + (g << 8) + (r << 16); ast->has_pal= 1; goto start_sync; } else if( ((ast->prefix_count<5 || sync+9 > i) && d[2]<128 && d[3]<128) || @@ -1052,7 +1051,7 @@ static int avi_read_packet(AVFormatContext *s, AVPacket *pkt) return AVERROR_EOF; best_ast = best_st->priv_data; - best_ts = av_rescale_q(best_ts, (AVRational){FFMAX(1, best_ast->sample_size), AV_TIME_BASE}, best_st->time_base); + best_ts = best_ast->frame_offset; if(best_ast->remaining) i= av_index_search_timestamp(best_st, best_ts, AVSEEK_FLAG_ANY | AVSEEK_FLAG_BACKWARD); else{ @@ -1229,6 +1228,9 @@ static int avi_read_idx1(AVFormatContext *s, int size) /* Read the entries and sort them in each stream component. */ for(i = 0; i < nb_index_entries; i++) { + if(url_feof(pb)) + return -1; + tag = avio_rl32(pb); flags = avio_rl32(pb); pos = avio_rl32(pb); @@ -1251,8 +1253,6 @@ static int avi_read_idx1(AVFormatContext *s, int size) av_dlog(s, "%d cum_len=%"PRId64"\n", len, ast->cum_len); - if(url_feof(pb)) - return -1; if(last_pos == pos) avi->non_interleaved= 1; @@ -1452,7 +1452,7 @@ static int avi_read_close(AVFormatContext *s) if (ast) { if (ast->sub_ctx) { av_freep(&ast->sub_ctx->pb); - av_close_input_file(ast->sub_ctx); + avformat_close_input(&ast->sub_ctx); } av_free(ast->sub_buffer); av_free_packet(&ast->sub_pkt);