Unified · Split
| @@ -21,6 +21,7 @@ · 20 unmodified lines | |||
| 21 | */ | 21 | */ |
| 22 | 22 | ||
| 23 | #include "avformat.h" | 23 | #include "avformat.h" |
| 24 | #include "avio_internal.h" | ||
| 24 | #include "demux.h" | 25 | #include "demux.h" |
| 25 | #include "internal.h" | 26 | #include "internal.h" |
| 26 | #include "libavutil/intreadwrite.h" | 27 | #include "libavutil/intreadwrite.h" |
| @@ -139,12 +140,10 @@ static int read_extradata(AVFormatContext *s, const ArgoBRPStreamHeader *hdr, · 112 unmodified lines | |||
| 139 | 140 | ||
| 140 | av_assert0(bufsz >= size); | 141 | av_assert0(bufsz >= size); |
| 141 | 142 | ||
| 142 | if ((ret = avio_read(s->pb, buf, size)) < 0) | 143 | ret = ffio_read_size(s->pb, buf, size); |
| 144 | if (ret < 0) | ||
| 143 | return ret; | 145 | return ret; |
| 144 | 146 | ||
| 145 | if (ret != size) | ||
| 146 | return AVERROR(EIO); | ||
| 147 | |||
| 148 | return 0; | 147 | return 0; |
| 149 | } | 148 | } |
| 150 | 149 | ||
| @@ -155,10 +154,9 @@ static int argo_brp_read_header(AVFormatContext *s) · 4 unmodified lines | |||
| 155 | ArgoBRPDemuxContext *brp = s->priv_data; | 154 | ArgoBRPDemuxContext *brp = s->priv_data; |
| 156 | uint8_t buf[FFMAX(BRP_MIN_BUFFER_SIZE, ASF_MIN_BUFFER_SIZE)]; | 155 | uint8_t buf[FFMAX(BRP_MIN_BUFFER_SIZE, ASF_MIN_BUFFER_SIZE)]; |
| 157 | 156 | ||
| 158 | if ((ret = avio_read(pb, buf, BRP_FILE_HEADER_SIZE)) < 0) | 157 | ret = ffio_read_size(pb, buf, BRP_FILE_HEADER_SIZE); |
| 158 | if (ret < 0) | ||
| 159 | return ret; | 159 | return ret; |
| 160 | else if (ret != BRP_FILE_HEADER_SIZE) | ||
| 161 | return AVERROR(EIO); | ||
| 162 | 160 | ||
| 163 | brp->fhdr.magic = AV_RL32(buf + 0); | 161 | brp->fhdr.magic = AV_RL32(buf + 0); |
| 164 | brp->fhdr.num_streams = AV_RL32(buf + 4); | 162 | brp->fhdr.num_streams = AV_RL32(buf + 4); |
| @@ -181,10 +179,9 @@ static int argo_brp_read_header(AVFormatContext *s) · 16 unmodified lines | |||
| 181 | if (!(st = avformat_new_stream(s, NULL))) | 179 | if (!(st = avformat_new_stream(s, NULL))) |
| 182 | return AVERROR(ENOMEM); | 180 | return AVERROR(ENOMEM); |
| 183 | 181 | ||
| 184 | if ((ret = avio_read(pb, buf, BRP_STREAM_HEADER_SIZE)) < 0) | 182 | ret = ffio_read_size(pb, buf, BRP_STREAM_HEADER_SIZE); |
| 183 | if (ret < 0) | ||
| 185 | return ret; | 184 | return ret; |
| 186 | else if (ret != BRP_STREAM_HEADER_SIZE) | ||
| 187 | return AVERROR(EIO); | ||
| 188 | 185 | ||
| 189 | hdr->codec_id = AV_RL32(buf + 0); | 186 | hdr->codec_id = AV_RL32(buf + 0); |
| 190 | hdr->id = AV_RL32(buf + 4); | 187 | hdr->id = AV_RL32(buf + 4); |
| @@ -286,10 +283,9 @@ static int argo_brp_read_header(AVFormatContext *s) · 95 unmodified lines | |||
| 286 | av_log(s, AV_LOG_TRACE, "Searching %d blocks for BASF...", BRP_BASF_LOOKAHEAD); | 283 | av_log(s, AV_LOG_TRACE, "Searching %d blocks for BASF...", BRP_BASF_LOOKAHEAD); |
| 287 | 284 | ||
| 288 | for (i = 0; i < BRP_BASF_LOOKAHEAD; i++) { | 285 | for (i = 0; i < BRP_BASF_LOOKAHEAD; i++) { |
| 289 | if ((ret = avio_read(pb, buf, BRP_BLOCK_HEADER_SIZE)) < 0) | 286 | ret = ffio_read_size(pb, buf, BRP_BLOCK_HEADER_SIZE); |
| 287 | if (ret < 0) | ||
| 290 | return ret; | 288 | return ret; |
| 291 | else if (ret != BRP_BLOCK_HEADER_SIZE) | ||
| 292 | return AVERROR(EIO); | ||
| 293 | 289 | ||
| 294 | blk.stream_id = AV_RL32(buf + 0); | 290 | blk.stream_id = AV_RL32(buf + 0); |
| 295 | blk.start_ms = AV_RL32(buf + 4); | 291 | blk.start_ms = AV_RL32(buf + 4); |
| @@ -313,10 +309,9 @@ static int argo_brp_read_header(AVFormatContext *s) · 17 unmodified lines | |||
| 313 | if (blk.size < ASF_CHUNK_HEADER_SIZE) | 309 | if (blk.size < ASF_CHUNK_HEADER_SIZE) |
| 314 | return AVERROR_INVALIDDATA; | 310 | return AVERROR_INVALIDDATA; |
| 315 | 311 | ||
| 316 | if ((ret = avio_read(pb, buf, ASF_CHUNK_HEADER_SIZE)) < 0) | 312 | ret = ffio_read_size(pb, buf, BRP_BLOCK_HEADER_SIZE); |
| 313 | if (ret < 0) | ||
| 317 | return ret; | 314 | return ret; |
| 318 | else if (ret != ASF_CHUNK_HEADER_SIZE) | ||
| 319 | return AVERROR(EIO); | ||
| 320 | 315 | ||
| 321 | ff_argo_asf_parse_chunk_header(&brp->basf.ckhdr, buf); | 316 | ff_argo_asf_parse_chunk_header(&brp->basf.ckhdr, buf); |
| 322 | 317 | ||
| @@ -358,10 +353,9 @@ static int argo_brp_read_packet(AVFormatContext *s, AVPacket *pkt) · 35 unmodified lines | |||
| 358 | ArgoASFChunkHeader ckhdr; | 353 | ArgoASFChunkHeader ckhdr; |
| 359 | int ret; | 354 | int ret; |
| 360 | 355 | ||
| 361 | if ((ret = avio_read(s->pb, buf, BRP_BLOCK_HEADER_SIZE)) < 0) | 356 | ret = ffio_read_size(s->pb, buf, BRP_BLOCK_HEADER_SIZE); |
| 357 | if (ret < 0) | ||
| 362 | return ret; | 358 | return ret; |
| 363 | else if (ret != BRP_BLOCK_HEADER_SIZE) | ||
| 364 | return AVERROR(EIO); | ||
| 365 | 359 | ||
| 366 | blk.stream_id = AV_RL32(buf + 0); | 360 | blk.stream_id = AV_RL32(buf + 0); |
| 367 | blk.start_ms = AV_RL32(buf + 4); | 361 | blk.start_ms = AV_RL32(buf + 4); |
| @@ -380,8 +374,9 @@ static int argo_brp_read_packet(AVFormatContext *s, AVPacket *pkt) · 12 unmodified lines | |||
| 380 | if (blk.size < ASF_CHUNK_HEADER_SIZE) | 374 | if (blk.size < ASF_CHUNK_HEADER_SIZE) |
| 381 | return AVERROR_INVALIDDATA; | 375 | return AVERROR_INVALIDDATA; |
| 382 | 376 | ||
| 383 | if (avio_read(s->pb, buf, ASF_CHUNK_HEADER_SIZE) != ASF_CHUNK_HEADER_SIZE) | 377 | ret = ffio_read_size(s->pb, buf, ASF_CHUNK_HEADER_SIZE); |
| 384 | return AVERROR_INVALIDDATA; | 378 | if (ret < 0) |
| 379 | return ret; | ||
| 385 | 380 | ||
| 386 | ff_argo_asf_parse_chunk_header(&ckhdr, buf); | 381 | ff_argo_asf_parse_chunk_header(&ckhdr, buf); |
| 387 | 382 | ||
| @@ -25,6 +25,7 @@ · 24 unmodified lines | |||
| 25 | #include "libavcodec/bytestream.h" | 25 | #include "libavcodec/bytestream.h" |
| 26 | #include "libavcodec/flac.h" | 26 | #include "libavcodec/flac.h" |
| 27 | #include "avformat.h" | 27 | #include "avformat.h" |
| 28 | #include "avio_internal.h" | ||
| 28 | #include "demux.h" | 29 | #include "demux.h" |
| 29 | #include "flac_picture.h" | 30 | #include "flac_picture.h" |
| 30 | #include "internal.h" | 31 | #include "internal.h" |
| @@ -100,11 +101,9 @@ static int flac_read_header(AVFormatContext *s) · 69 unmodified lines | |||
| 100 | if (!buffer) { | 101 | if (!buffer) { |
| 101 | return AVERROR(ENOMEM); | 102 | return AVERROR(ENOMEM); |
| 102 | } | 103 | } |
| 103 | ret = avio_read(s->pb, buffer, metadata_size); | 104 | ret = ffio_read_size(s->pb, buffer, metadata_size); |
| 104 | if (ret < 0) { | 105 | if (ret < 0) { |
| 105 | RETURN_ERROR(ret); | 106 | RETURN_ERROR(ret); |
| 106 | } else if (ret != metadata_size) { | ||
| 107 | RETURN_ERROR(AVERROR_EOF); | ||
| 108 | } | 107 | } |
| 109 | break; | 108 | break; |
| 110 | /* skip metadata block for unsupported types */ | 109 | /* skip metadata block for unsupported types */ |
| @@ -22,6 +22,7 @@ · 21 unmodified lines | |||
| 22 | #include "config_components.h" | 22 | #include "config_components.h" |
| 23 | 23 | ||
| 24 | #include "avformat.h" | 24 | #include "avformat.h" |
| 25 | #include "avio_internal.h" | ||
| 25 | #include "demux.h" | 26 | #include "demux.h" |
| 26 | #include "internal.h" | 27 | #include "internal.h" |
| 27 | #include "mux.h" | 28 | #include "mux.h" |
| @@ -60,9 +61,11 @@ static int ilbc_read_header(AVFormatContext *s) · 32 unmodified lines | |||
| 60 | AVIOContext *pb = s->pb; | 61 | AVIOContext *pb = s->pb; |
| 61 | AVStream *st; | 62 | AVStream *st; |
| 62 | uint8_t header[9]; | 63 | uint8_t header[9]; |
| 64 | int ret; | ||
| 63 | 65 | ||
| 64 | if (avio_read(pb, header, 9) != 9) | 66 | ret = ffio_read_size(pb, header, 9); |
| 65 | return AVERROR_INVALIDDATA; | 67 | if (ret < 0) |
| 68 | return ret; | ||
| 66 | 69 | ||
| 67 | st = avformat_new_stream(s, NULL); | 70 | st = avformat_new_stream(s, NULL); |
| 68 | if (!st) | 71 | if (!st) |
| @@ -35,6 +35,7 @@ · 34 unmodified lines | |||
| 35 | #include "libavutil/channel_layout.h" | 35 | #include "libavutil/channel_layout.h" |
| 36 | #include "libavutil/intreadwrite.h" | 36 | #include "libavutil/intreadwrite.h" |
| 37 | #include "avformat.h" | 37 | #include "avformat.h" |
| 38 | #include "avio_internal.h" | ||
| 38 | #include "demux.h" | 39 | #include "demux.h" |
| 39 | #include "internal.h" | 40 | #include "internal.h" |
| 40 | 41 | ||
| @@ -611,11 +612,13 @@ static int ipmovie_read_header(AVFormatContext *s) · 570 unmodified lines | |||
| 611 | unsigned char chunk_preamble[CHUNK_PREAMBLE_SIZE]; | 612 | unsigned char chunk_preamble[CHUNK_PREAMBLE_SIZE]; |
| 612 | int chunk_type, i; | 613 | int chunk_type, i; |
| 613 | uint8_t signature_buffer[sizeof(signature)]; | 614 | uint8_t signature_buffer[sizeof(signature)]; |
| 615 | int ret; | ||
| 614 | 616 | ||
| 615 | ipmovie->avf = s; | 617 | ipmovie->avf = s; |
| 616 | 618 | ||
| 617 | if (avio_read(pb, signature_buffer, sizeof(signature_buffer)) != sizeof(signature_buffer)) | 619 | ret = ffio_read_size(pb, signature_buffer, sizeof(signature_buffer)); |
| 618 | return AVERROR_INVALIDDATA; | 620 | if (ret < 0) |
| 621 | return ret; | ||
| 619 | while (memcmp(signature_buffer, signature, sizeof(signature))) { | 622 | while (memcmp(signature_buffer, signature, sizeof(signature))) { |
| 620 | memmove(signature_buffer, signature_buffer + 1, sizeof(signature_buffer) - 1); | 623 | memmove(signature_buffer, signature_buffer + 1, sizeof(signature_buffer) - 1); |
| 621 | signature_buffer[sizeof(signature_buffer) - 1] = avio_r8(pb); | 624 | signature_buffer[sizeof(signature_buffer) - 1] = avio_r8(pb); |
| @@ -34,6 +34,7 @@ · 33 unmodified lines | |||
| 34 | #include "libavutil/channel_layout.h" | 34 | #include "libavutil/channel_layout.h" |
| 35 | #include "libavutil/intreadwrite.h" | 35 | #include "libavutil/intreadwrite.h" |
| 36 | #include "avformat.h" | 36 | #include "avformat.h" |
| 37 | #include "avio_internal.h" | ||
| 37 | #include "demux.h" | 38 | #include "demux.h" |
| 38 | #include "internal.h" | 39 | #include "internal.h" |
| 39 | 40 | ||
| @@ -144,8 +145,9 @@ static int read_packet(AVFormatContext *s, · 104 unmodified lines | |||
| 144 | if (avio_feof(pb)) | 145 | if (avio_feof(pb)) |
| 145 | return AVERROR_EOF; | 146 | return AVERROR_EOF; |
| 146 | 147 | ||
| 147 | if (avio_read(pb, preamble, MM_PREAMBLE_SIZE) != MM_PREAMBLE_SIZE) | 148 | ret = ffio_read_size(pb, preamble, MM_PREAMBLE_SIZE); |
| 148 | return AVERROR(EIO); | 149 | if (ret < 0) |
| 150 | return ret; | ||
| 149 | 151 | ||
| 150 | type = AV_RL16(&preamble[0]); | 152 | type = AV_RL16(&preamble[0]); |
| 151 | length = AV_RL16(&preamble[2]); | 153 | length = AV_RL16(&preamble[2]); |
| @@ -163,8 +165,9 @@ static int read_packet(AVFormatContext *s, · 11 unmodified lines | |||
| 163 | if ((ret = av_new_packet(pkt, length + MM_PREAMBLE_SIZE)) < 0) | 165 | if ((ret = av_new_packet(pkt, length + MM_PREAMBLE_SIZE)) < 0) |
| 164 | return ret; | 166 | return ret; |
| 165 | memcpy(pkt->data, preamble, MM_PREAMBLE_SIZE); | 167 | memcpy(pkt->data, preamble, MM_PREAMBLE_SIZE); |
| 166 | if (avio_read(pb, pkt->data + MM_PREAMBLE_SIZE, length) != length) | 168 | ret = ffio_read_size(pb, pkt->data + MM_PREAMBLE_SIZE, length); |
| 167 | return AVERROR(EIO); | 169 | if (ret < 0) |
| 170 | return ret; | ||
| 168 | pkt->size = length + MM_PREAMBLE_SIZE; | 171 | pkt->size = length + MM_PREAMBLE_SIZE; |
| 169 | pkt->stream_index = 0; | 172 | pkt->stream_index = 0; |
| 170 | if (type!=MM_TYPE_PALETTE) | 173 | if (type!=MM_TYPE_PALETTE) |
| @@ -566,9 +566,9 @@ redo: · 565 unmodified lines | |||
| 566 | static const unsigned char avs_seqh[4] = { 0, 0, 1, 0xb0 }; | 566 | static const unsigned char avs_seqh[4] = { 0, 0, 1, 0xb0 }; |
| 567 | unsigned char buf[8]; | 567 | unsigned char buf[8]; |
| 568 | 568 | ||
| 569 | ret = avio_read(s->pb, buf, 8); | 569 | ret = ffio_read_size(s->pb, buf, 8); |
| 570 | if (ret != 8) | 570 | if (ret < 0) |
| 571 | return AVERROR_INVALIDDATA; | 571 | return ret; |
| 572 | avio_seek(s->pb, -8, SEEK_CUR); | 572 | avio_seek(s->pb, -8, SEEK_CUR); |
| 573 | if (!memcmp(buf, avs_seqh, 4) && (buf[6] != 0 || buf[7] != 1)) | 573 | if (!memcmp(buf, avs_seqh, 4) && (buf[6] != 0 || buf[7] != 1)) |
| 574 | codec_id = AV_CODEC_ID_CAVS; | 574 | codec_id = AV_CODEC_ID_CAVS; |
| @@ -62,6 +62,7 @@ · 61 unmodified lines | |||
| 62 | #include "libavutil/opt.h" | 62 | #include "libavutil/opt.h" |
| 63 | #include "avformat.h" | 63 | #include "avformat.h" |
| 64 | #include "avlanguage.h" | 64 | #include "avlanguage.h" |
| 65 | #include "avio_internal.h" | ||
| 65 | #include "demux.h" | 66 | #include "demux.h" |
| 66 | #include "internal.h" | 67 | #include "internal.h" |
| 67 | #include "mxf.h" | 68 | #include "mxf.h" |
| @@ -659,6 +660,7 @@ static int mxf_decrypt_triplet(AVFormatContext *s, AVPacket *pkt, KLVPacket *klv · 591 unmodified lines | |||
| 659 | uint64_t plaintext_size; | 660 | uint64_t plaintext_size; |
| 660 | uint8_t ivec[16]; | 661 | uint8_t ivec[16]; |
| 661 | uint8_t tmpbuf[16]; | 662 | uint8_t tmpbuf[16]; |
| 663 | int ret; | ||
| 662 | int index; | 664 | int index; |
| 663 | int body_sid; | 665 | int body_sid; |
| 664 | 666 | ||
| @@ -696,8 +698,9 @@ static int mxf_decrypt_triplet(AVFormatContext *s, AVPacket *pkt, KLVPacket *klv · 31 unmodified lines | |||
| 696 | if (size < 32 || size - 32 < orig_size || (int)orig_size != orig_size) | 698 | if (size < 32 || size - 32 < orig_size || (int)orig_size != orig_size) |
| 697 | return AVERROR_INVALIDDATA; | 699 | return AVERROR_INVALIDDATA; |
| 698 | avio_read(pb, ivec, 16); | 700 | avio_read(pb, ivec, 16); |
| 699 | if (avio_read(pb, tmpbuf, 16) != 16) | 701 | ret = ffio_read_size(pb, tmpbuf, 16); |
| 700 | return AVERROR_INVALIDDATA; | 702 | if (ret < 16) |
| 703 | return ret; | ||
| 701 | if (mxf->aesc) | 704 | if (mxf->aesc) |
| 702 | av_aes_crypt(mxf->aesc, tmpbuf, tmpbuf, 1, ivec, 1); | 705 | av_aes_crypt(mxf->aesc, tmpbuf, tmpbuf, 1, ivec, 1); |
| 703 | if (memcmp(tmpbuf, checkv, 16)) | 706 | if (memcmp(tmpbuf, checkv, 16)) |
| @@ -753,6 +756,7 @@ static int mxf_read_partition_pack(void *arg, AVIOContext *pb, int tag, int size · 49 unmodified lines | |||
| 753 | uint64_t footer_partition; | 756 | uint64_t footer_partition; |
| 754 | uint32_t nb_essence_containers; | 757 | uint32_t nb_essence_containers; |
| 755 | uint64_t this_partition; | 758 | uint64_t this_partition; |
| 759 | int ret; | ||
| 756 | 760 | ||
| 757 | if (mxf->partitions_count >= INT_MAX / 2) | 761 | if (mxf->partitions_count >= INT_MAX / 2) |
| 758 | return AVERROR_INVALIDDATA; | 762 | return AVERROR_INVALIDDATA; |
| @@ -818,9 +822,10 @@ static int mxf_read_partition_pack(void *arg, AVIOContext *pb, int tag, int size · 59 unmodified lines | |||
| 818 | if (partition->body_offset < 0) | 822 | if (partition->body_offset < 0) |
| 819 | return AVERROR_INVALIDDATA; | 823 | return AVERROR_INVALIDDATA; |
| 820 | 824 | ||
| 821 | if (avio_read(pb, op, sizeof(UID)) != sizeof(UID)) { | 825 | ret = ffio_read_size(pb, op, sizeof(UID)); |
| 826 | if (ret < 0) { | ||
| 822 | av_log(mxf->fc, AV_LOG_ERROR, "Failed reading UID\n"); | 827 | av_log(mxf->fc, AV_LOG_ERROR, "Failed reading UID\n"); |
| 823 | return AVERROR_INVALIDDATA; | 828 | return ret; |
| 824 | } | 829 | } |
| 825 | nb_essence_containers = avio_rb32(pb); | 830 | nb_essence_containers = avio_rb32(pb); |
| 826 | 831 | ||
| @@ -1552,12 +1557,14 @@ static int mxf_read_indirect_value(void *arg, AVIOContext *pb, int size) · 725 unmodified lines | |||
| 1552 | { | 1557 | { |
| 1553 | MXFTaggedValue *tagged_value = arg; | 1558 | MXFTaggedValue *tagged_value = arg; |
| 1554 | uint8_t key[17]; | 1559 | uint8_t key[17]; |
| 1560 | int ret; | ||
| 1555 | 1561 | ||
| 1556 | if (size <= 17) | 1562 | if (size <= 17) |
| 1557 | return 0; | 1563 | return 0; |
| 1558 | 1564 | ||
| 1559 | if (avio_read(pb, key, 17) != 17) | 1565 | ret = ffio_read_size(pb, key, 17); |
| 1560 | return AVERROR_INVALIDDATA; | 1566 | if (ret < 0) |
| 1567 | return ret; | ||
| 1561 | /* TODO: handle other types of of indirect values */ | 1568 | /* TODO: handle other types of of indirect values */ |
| 1562 | if (memcmp(key, mxf_indirect_value_utf16le, 17) == 0) { | 1569 | if (memcmp(key, mxf_indirect_value_utf16le, 17) == 0) { |
| 1563 | return mxf_read_utf16le_string(pb, size - 17, &tagged_value->value); | 1570 | return mxf_read_utf16le_string(pb, size - 17, &tagged_value->value); |
| @@ -30,6 +30,7 @@ · 29 unmodified lines | |||
| 30 | #include "libavutil/channel_layout.h" | 30 | #include "libavutil/channel_layout.h" |
| 31 | #include "libavutil/intreadwrite.h" | 31 | #include "libavutil/intreadwrite.h" |
| 32 | #include "avformat.h" | 32 | #include "avformat.h" |
| 33 | #include "avio_internal.h" | ||
| 33 | #include "demux.h" | 34 | #include "demux.h" |
| 34 | #include "riff.h" | 35 | #include "riff.h" |
| 35 | 36 | ||
| @@ -94,6 +95,7 @@ static int qcp_read_header(AVFormatContext *s) · 58 unmodified lines | |||
| 94 | QCPContext *c = s->priv_data; | 95 | QCPContext *c = s->priv_data; |
| 95 | AVStream *st = avformat_new_stream(s, NULL); | 96 | AVStream *st = avformat_new_stream(s, NULL); |
| 96 | uint8_t buf[16]; | 97 | uint8_t buf[16]; |
| 98 | int ret; | ||
| 97 | int i; | 99 | int i; |
| 98 | unsigned nb_rates; | 100 | unsigned nb_rates; |
| 99 | 101 | ||
| @@ -105,8 +107,9 @@ static int qcp_read_header(AVFormatContext *s) · 5 unmodified lines | |||
| 105 | 107 | ||
| 106 | st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; | 108 | st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; |
| 107 | st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO; | 109 | st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO; |
| 108 | if (avio_read(pb, buf, 16) != 16) | 110 | ret = ffio_read_size(pb, buf, 16); |
| 109 | return AVERROR_INVALIDDATA; | 111 | if (ret < 0) |
| 112 | return ret; | ||
| 110 | if (is_qcelp_13k_guid(buf)) { | 113 | if (is_qcelp_13k_guid(buf)) { |
| 111 | st->codecpar->codec_id = AV_CODEC_ID_QCELP; | 114 | st->codecpar->codec_id = AV_CODEC_ID_QCELP; |
| 112 | } else if (!memcmp(buf, guid_evrc, 16)) { | 115 | } else if (!memcmp(buf, guid_evrc, 16)) { |
| @@ -188,8 +188,9 @@ static int rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb, · 187 unmodified lines | |||
| 188 | st->codecpar->ch_layout.nb_channels = avio_rb16(pb); | 188 | st->codecpar->ch_layout.nb_channels = avio_rb16(pb); |
| 189 | if (version == 5) { | 189 | if (version == 5) { |
| 190 | ast->deint_id = avio_rl32(pb); | 190 | ast->deint_id = avio_rl32(pb); |
| 191 | if (avio_read(pb, buf, 4) != 4) | 191 | ret = ffio_read_size(pb, buf, 4); |
| 192 | return AVERROR_INVALIDDATA; | 192 | if (ret < 0) |
| 193 | return ret; | ||
| 193 | buf[4] = 0; | 194 | buf[4] = 0; |
| 194 | } else { | 195 | } else { |
| 195 | AV_WL32(buf, 0); | 196 | AV_WL32(buf, 0); |
| @@ -816,10 +817,11 @@ static int rm_assemble_video_frame(AVFormatContext *s, AVIOContext *pb, · 620 unmodified lines | |||
| 816 | pkt->data[0] = 0; | 817 | pkt->data[0] = 0; |
| 817 | AV_WL32(pkt->data + 1, 1); | 818 | AV_WL32(pkt->data + 1, 1); |
| 818 | AV_WL32(pkt->data + 5, 0); | 819 | AV_WL32(pkt->data + 5, 0); |
| 819 | if ((ret = avio_read(pb, pkt->data + 9, len)) != len) { | 820 | ret = ffio_read_size(pb, pkt->data + 9, len); |
| 821 | if (ret < 0) { | ||
| 820 | av_packet_unref(pkt); | 822 | av_packet_unref(pkt); |
| 821 | av_log(s, AV_LOG_ERROR, "Failed to read %d bytes\n", len); | 823 | av_log(s, AV_LOG_ERROR, "Failed to read %d bytes\n", len); |
| 822 | return ret < 0 ? ret : AVERROR(EIO); | 824 | return ret; |
| 823 | } | 825 | } |
| 824 | return 0; | 826 | return 0; |
| 825 | } | 827 | } |
| @@ -856,8 +858,9 @@ static int rm_assemble_video_frame(AVFormatContext *s, AVIOContext *pb, · 30 unmodified lines | |||
| 856 | av_log(s, AV_LOG_ERROR, "outside videobufsize\n"); | 858 | av_log(s, AV_LOG_ERROR, "outside videobufsize\n"); |
| 857 | return 1; | 859 | return 1; |
| 858 | } | 860 | } |
| 859 | if (avio_read(pb, vst->pkt.data + vst->videobufpos, len) != len) | 861 | ret = ffio_read_size(pb, vst->pkt.data + vst->videobufpos, len); |
| 860 | return AVERROR(EIO); | 862 | if (ret < 0) |
| 863 | return ret; | ||
| 861 | vst->videobufpos += len; | 864 | vst->videobufpos += len; |
| 862 | rm->remaining_len-= len; | 865 | rm->remaining_len-= len; |
| 863 | 866 | ||
| @@ -96,10 +96,10 @@ static int tak_read_header(AVFormatContext *s) · 95 unmodified lines | |||
| 96 | memset(buffer + size - 3, 0, AV_INPUT_BUFFER_PADDING_SIZE); | 96 | memset(buffer + size - 3, 0, AV_INPUT_BUFFER_PADDING_SIZE); |
| 97 | 97 | ||
| 98 | ffio_init_checksum(pb, tak_check_crc, 0xCE04B7U); | 98 | ffio_init_checksum(pb, tak_check_crc, 0xCE04B7U); |
| 99 | ret = avio_read(pb, buffer, size - 3); | 99 | ret = ffio_read_size(pb, buffer, size - 3); |
| 100 | if (ret != size - 3) { | 100 | if (ret < 0) { |
| 101 | av_freep(&buffer); | 101 | av_freep(&buffer); |
| 102 | return ret < 0 ? ret : AVERROR_INVALIDDATA; | 102 | return ret; |
| 103 | } | 103 | } |
| 104 | if (ffio_get_checksum(s->pb) != avio_rb24(pb)) { | 104 | if (ffio_get_checksum(s->pb) != avio_rb24(pb)) { |
| 105 | av_log(s, AV_LOG_ERROR, "%d metadata block CRC error.\n", type); | 105 | av_log(s, AV_LOG_ERROR, "%d metadata block CRC error.\n", type); |
| @@ -117,9 +117,9 @@ static int tak_read_header(AVFormatContext *s) · 11 unmodified lines | |||
| 117 | if (size != 19) | 117 | if (size != 19) |
| 118 | return AVERROR_INVALIDDATA; | 118 | return AVERROR_INVALIDDATA; |
| 119 | ffio_init_checksum(pb, tak_check_crc, 0xCE04B7U); | 119 | ffio_init_checksum(pb, tak_check_crc, 0xCE04B7U); |
| 120 | ret = avio_read(pb, md5, 16); | 120 | ret = ffio_read_size(pb, md5, 16); |
| 121 | if (ret != 16) | 121 | if (ret < 0) |
| 122 | return ret < 0 ? ret : AVERROR_INVALIDDATA; | 122 | return ret; |
| 123 | if (ffio_get_checksum(s->pb) != avio_rb24(pb)) { | 123 | if (ffio_get_checksum(s->pb) != avio_rb24(pb)) { |
| 124 | av_log(s, AV_LOG_ERROR, "MD5 metadata block CRC error.\n"); | 124 | av_log(s, AV_LOG_ERROR, "MD5 metadata block CRC error.\n"); |
| 125 | if (s->error_recognition & AV_EF_EXPLODE) | 125 | if (s->error_recognition & AV_EF_EXPLODE) |
| @@ -567,8 +567,9 @@ static int viv_read_header(AVFormatContext *s) · 566 unmodified lines | |||
| 567 | v = avio_r8(pb); | 567 | v = avio_r8(pb); |
| 568 | avio_seek(pb, v, SEEK_CUR); | 568 | avio_seek(pb, v, SEEK_CUR); |
| 569 | 569 | ||
| 570 | if (avio_read(pb, keybuffer, 187) != 187) | 570 | ret = ffio_read_size(pb, keybuffer, 187); |
| 571 | return AVERROR_INVALIDDATA; | 571 | if (ret < 0) |
| 572 | return ret; | ||
| 572 | key = decode_key(keybuffer); | 573 | key = decode_key(keybuffer); |
| 573 | viv->sb_key = key; | 574 | viv->sb_key = key; |
| 574 | 575 | ||
| @@ -20,6 +20,7 @@ · 19 unmodified lines | |||
| 20 | */ | 20 | */ |
| 21 | 21 | ||
| 22 | #include "avformat.h" | 22 | #include "avformat.h" |
| 23 | #include "avio_internal.h" | ||
| 23 | #include "demux.h" | 24 | #include "demux.h" |
| 24 | #include "internal.h" | 25 | #include "internal.h" |
| 25 | #include "libavutil/intreadwrite.h" | 26 | #include "libavutil/intreadwrite.h" |
| @@ -65,10 +66,10 @@ static int add_metadata(AVFormatContext *s, uint32_t tag, · 39 unmodified lines | |||
| 65 | if (!buf) | 66 | if (!buf) |
| 66 | return AVERROR(ENOMEM); | 67 | return AVERROR(ENOMEM); |
| 67 | 68 | ||
| 68 | ret = avio_read(s->pb, buf, len); | 69 | ret = ffio_read_size(s->pb, buf, len); |
| 69 | if (ret < 0 || ret != len) { | 70 | if (ret < 0) { |
| 70 | av_free(buf); | 71 | av_free(buf); |
| 71 | return ret < 0 ? ret : AVERROR_INVALIDDATA; | 72 | return ret; |
| 72 | } | 73 | } |
| 73 | buf[len] = 0; | 74 | buf[len] = 0; |
| 74 | AV_WL32(key, tag); | 75 | AV_WL32(key, tag); |
| @@ -259,11 +260,9 @@ static int vqf_read_packet(AVFormatContext *s, AVPacket *pkt) · 184 unmodified lines | |||
| 259 | 260 | ||
| 260 | pkt->data[0] = 8 - c->remaining_bits; // Number of bits to skip | 261 | pkt->data[0] = 8 - c->remaining_bits; // Number of bits to skip |
| 261 | pkt->data[1] = c->last_frame_bits; | 262 | pkt->data[1] = c->last_frame_bits; |
| 262 | ret = avio_read(s->pb, pkt->data+2, size); | 263 | ret = ffio_read_size(s->pb, pkt->data + 2, size); |
| 263 | 264 | if (ret < 0) | |
| 264 | if (ret != size) { | 265 | return ret; |
| 265 | return AVERROR(EIO); | ||
| 266 | } | ||
| 267 | 266 | ||
| 268 | c->last_frame_bits = pkt->data[size+1]; | 267 | c->last_frame_bits = pkt->data[size+1]; |
| 269 | c->remaining_bits = (size << 3) - c->frame_bit_len + c->remaining_bits; | 268 | c->remaining_bits = (size << 3) - c->frame_bit_len + c->remaining_bits; |
| @@ -872,9 +872,12 @@ static int w64_read_header(AVFormatContext *s) · 871 unmodified lines | |||
| 872 | WAVDemuxContext *wav = s->priv_data; | 872 | WAVDemuxContext *wav = s->priv_data; |
| 873 | AVStream *st; | 873 | AVStream *st; |
| 874 | uint8_t guid[16]; | 874 | uint8_t guid[16]; |
| 875 | int ret; | 875 | int ret = ffio_read_size(pb, guid, 16); |
| 876 | |||
| 877 | if (ret < 0) | ||
| 878 | return ret; | ||
| 876 | 879 | ||
| 877 | if (avio_read(pb, guid, 16) != 16 || memcmp(guid, ff_w64_guid_riff, 16)) | 880 | if (memcmp(guid, ff_w64_guid_riff, 16)) |
| 878 | return AVERROR_INVALIDDATA; | 881 | return AVERROR_INVALIDDATA; |
| 879 | 882 | ||
| 880 | /* riff + wave + fmt + sizes */ | 883 | /* riff + wave + fmt + sizes */ |
| @@ -34,6 +34,7 @@ · 33 unmodified lines | |||
| 34 | #include "libavutil/mem.h" | 34 | #include "libavutil/mem.h" |
| 35 | #include "libavutil/time_internal.h" | 35 | #include "libavutil/time_internal.h" |
| 36 | #include "avformat.h" | 36 | #include "avformat.h" |
| 37 | #include "avio_internal.h" | ||
| 37 | #include "demux.h" | 38 | #include "demux.h" |
| 38 | #include "internal.h" | 39 | #include "internal.h" |
| 39 | #include "wtv.h" | 40 | #include "wtv.h" |
| @@ -774,6 +775,7 @@ static int parse_chunks(AVFormatContext *s, int mode, int64_t seekts, int *len_p · 734 unmodified lines | |||
| 774 | { | 775 | { |
| 775 | WtvContext *wtv = s->priv_data; | 776 | WtvContext *wtv = s->priv_data; |
| 776 | AVIOContext *pb = wtv->pb; | 777 | AVIOContext *pb = wtv->pb; |
| 778 | int ret; | ||
| 777 | while (!avio_feof(pb)) { | 779 | while (!avio_feof(pb)) { |
| 778 | ff_asf_guid g; | 780 | ff_asf_guid g; |
| 779 | int len, sid, consumed; | 781 | int len, sid, consumed; |
| @@ -846,8 +848,9 @@ static int parse_chunks(AVFormatContext *s, int mode, int64_t seekts, int *len_p · 66 unmodified lines | |||
| 846 | } | 848 | } |
| 847 | 849 | ||
| 848 | buf_size = FFMIN(len - consumed, sizeof(buf)); | 850 | buf_size = FFMIN(len - consumed, sizeof(buf)); |
| 849 | if (avio_read(pb, buf, buf_size) != buf_size) | 851 | ret = ffio_read_size(pb, buf, buf_size); |
| 850 | return AVERROR_INVALIDDATA; | 852 | if (ret < 0) |
| 853 | return ret; | ||
| 851 | consumed += buf_size; | 854 | consumed += buf_size; |
| 852 | ff_parse_mpeg2_descriptor(s, st, 0, &pbuf, buf + buf_size, NULL, 0, 0, NULL); | 855 | ff_parse_mpeg2_descriptor(s, st, 0, &pbuf, buf + buf_size, NULL, 0, 0, NULL); |
| 853 | } | 856 | } |