Unified · Split
| @@ -113,6 +113,7 @@ static const AVMetadataConv avi_metadata_conv[] = { · 112 unmodified lines | ||
| 113 | 113 | { 0 }, |
| 114 | 114 | }; |
| 115 | 115 | |
| 116 | +static int avi_read_close(AVFormatContext *s); | |
| 116 | 117 | static int avi_load_index(AVFormatContext *s); |
| 117 | 118 | static int guess_ni_flag(AVFormatContext *s); |
| 118 | 119 | |
| @@ -464,6 +465,7 @@ static int calculate_bitrate(AVFormatContext *s) · 345 unmodified lines | ||
| 464 | 465 | return 1; |
| 465 | 466 | } |
| 466 | 467 | |
| 468 | +#define RETURN_ERROR(code) do { ret = (code); goto fail; } while (0) | |
| 467 | 469 | static int avi_read_header(AVFormatContext *s) |
| 468 | 470 | { |
| 469 | 471 | AVIContext *avi = s->priv_data; |
| @@ -499,7 +501,7 @@ static int avi_read_header(AVFormatContext *s) · 29 unmodified lines | ||
| 499 | 501 | frame_period = 0; |
| 500 | 502 | for (;;) { |
| 501 | 503 | if (avio_feof(pb)) |
| 502 | − goto fail; | |
| 504 | + RETURN_ERROR(AVERROR_INVALIDDATA); | |
| 503 | 505 | tag = avio_rl32(pb); |
| 504 | 506 | size = avio_rl32(pb); |
| 505 | 507 | |
| @@ -571,12 +573,12 @@ static int avi_read_header(AVFormatContext *s) · 65 unmodified lines | ||
| 571 | 573 | stream_index++; |
| 572 | 574 | st = avformat_new_stream(s, NULL); |
| 573 | 575 | if (!st) |
| 574 | − goto fail; | |
| 576 | + RETURN_ERROR(AVERROR(ENOMEM)); | |
| 575 | 577 | |
| 576 | 578 | st->id = stream_index; |
| 577 | 579 | ast = av_mallocz(sizeof(AVIStream)); |
| 578 | 580 | if (!ast) |
| 579 | − goto fail; | |
| 581 | + RETURN_ERROR(AVERROR(ENOMEM)); | |
| 580 | 582 | st->priv_data = ast; |
| 581 | 583 | } |
| 582 | 584 | if (amv_file_format) |
| @@ -592,12 +594,12 @@ static int avi_read_header(AVFormatContext *s) · 9 unmodified lines | ||
| 592 | 594 | /* After some consideration -- I don't think we |
| 593 | 595 | * have to support anything but DV in type1 AVIs. */ |
| 594 | 596 | if (s->nb_streams != 1) |
| 595 | − goto fail; | |
| 597 | + RETURN_ERROR(AVERROR_INVALIDDATA); | |
| 596 | 598 | |
| 597 | 599 | if (handler != MKTAG('d', 'v', 's', 'd') && |
| 598 | 600 | handler != MKTAG('d', 'v', 'h', 'd') && |
| 599 | 601 | handler != MKTAG('d', 'v', 's', 'l')) |
| 600 | − goto fail; | |
| 602 | + return AVERROR_INVALIDDATA; | |
| 601 | 603 | |
| 602 | 604 | if (!CONFIG_DV_DEMUXER) |
| 603 | 605 | return AVERROR_DEMUXER_NOT_FOUND; |
| @@ -697,7 +699,7 @@ static int avi_read_header(AVFormatContext *s) · 93 unmodified lines | ||
| 697 | 699 | "Invalid sample_size %d at stream %d\n", |
| 698 | 700 | ast->sample_size, |
| 699 | 701 | stream_index); |
| 700 | − goto fail; | |
| 702 | + RETURN_ERROR(AVERROR_INVALIDDATA); | |
| 701 | 703 | } |
| 702 | 704 | av_log(s, AV_LOG_WARNING, |
| 703 | 705 | "Invalid sample_size %d at stream %d " |
| @@ -927,7 +929,7 @@ static int avi_read_header(AVFormatContext *s) · 223 unmodified lines | ||
| 927 | 929 | av_log(s, AV_LOG_WARNING, "New extradata in strd chunk, freeing previous one.\n"); |
| 928 | 930 | } |
| 929 | 931 | if ((ret = ff_get_extradata(s, st->codecpar, pb, size)) < 0) |
| 930 | − return ret; | |
| 932 | + goto fail; | |
| 931 | 933 | } |
| 932 | 934 | |
| 933 | 935 | if (st->codecpar->extradata_size & 1) //FIXME check if the encoder really did this correctly |
| @@ -945,7 +947,7 @@ static int avi_read_header(AVFormatContext *s) · 11 unmodified lines | ||
| 945 | 947 | avi->use_odml && |
| 946 | 948 | read_odml_index(s, 0) < 0 && |
| 947 | 949 | (s->error_recognition & AV_EF_EXPLODE)) |
| 948 | − goto fail; | |
| 950 | + RETURN_ERROR(AVERROR_INVALIDDATA); | |
| 949 | 951 | avio_seek(pb, pos + size, SEEK_SET); |
| 950 | 952 | break; |
| 951 | 953 | case MKTAG('v', 'p', 'r', 'p'): |
| @@ -980,7 +982,7 @@ static int avi_read_header(AVFormatContext *s) · 28 unmodified lines | ||
| 980 | 982 | if (s->nb_streams) { |
| 981 | 983 | ret = avi_read_tag(s, s->streams[s->nb_streams - 1], tag, size); |
| 982 | 984 | if (ret < 0) |
| 983 | − return ret; | |
| 985 | + goto fail; | |
| 984 | 986 | break; |
| 985 | 987 | } |
| 986 | 988 | default: |
| @@ -991,7 +993,7 @@ static int avi_read_header(AVFormatContext *s) · 4 unmodified lines | ||
| 991 | 993 | "I will ignore it and try to continue anyway.\n", |
| 992 | 994 | av_fourcc2str(tag), size); |
| 993 | 995 | if (s->error_recognition & AV_EF_EXPLODE) |
| 994 | − goto fail; | |
| 996 | + RETURN_ERROR(AVERROR_INVALIDDATA); | |
| 995 | 997 | avi->movi_list = avio_tell(pb) - 4; |
| 996 | 998 | avi->movi_end = avi->fsize; |
| 997 | 999 | goto end_of_header; |
| @@ -1008,9 +1010,7 @@ static int avi_read_header(AVFormatContext *s) · 10 unmodified lines | ||
| 1008 | 1010 | end_of_header: |
| 1009 | 1011 | /* check stream number */ |
| 1010 | 1012 | if (stream_index != s->nb_streams - 1) { |
| 1011 | − | |
| 1012 | −fail: | |
| 1013 | − return AVERROR_INVALIDDATA; | |
| 1013 | + RETURN_ERROR(AVERROR_INVALIDDATA); | |
| 1014 | 1014 | } |
| 1015 | 1015 | |
| 1016 | 1016 | if (!avi->index_loaded && (pb->seekable & AVIO_SEEKABLE_NORMAL)) |
| @@ -1019,7 +1019,7 @@ fail: · 2 unmodified lines | ||
| 1019 | 1019 | avi->index_loaded |= 1; |
| 1020 | 1020 | |
| 1021 | 1021 | if ((ret = guess_ni_flag(s)) < 0) |
| 1022 | − return ret; | |
| 1022 | + goto fail; | |
| 1023 | 1023 | |
| 1024 | 1024 | avi->non_interleaved |= ret | (s->flags & AVFMT_FLAG_SORT_DTS); |
| 1025 | 1025 | |
| @@ -1056,6 +1056,9 @@ fail: · 30 unmodified lines | ||
| 1056 | 1056 | ff_metadata_conv_ctx(s, NULL, ff_riff_info_conv); |
| 1057 | 1057 | |
| 1058 | 1058 | return 0; |
| 1059 | +fail: | |
| 1060 | + avi_read_close(s); | |
| 1061 | + return ret; | |
| 1059 | 1062 | } |
| 1060 | 1063 | |
| 1061 | 1064 | static int read_gab2_sub(AVFormatContext *s, AVStream *st, AVPacket *pkt) |