History

avformat: Use ffio_read_size() where appropriate

Andreas Rheinhardt committed 1 year ago

Commit 6dd83fa1 parent 122f86d14 files · +91 −69Browse files

Unified · Split

14 files
  1. libavformat/argo_brp.c +16 −21
  2. libavformat/flacdec.c +2 −3
  3. libavformat/ilbc.c +5 −2
  4. libavformat/ipmovie.c +5 −2
  5. libavformat/mm.c +7 −4
  6. libavformat/mpeg.c +3 −3
  7. libavformat/mxfdec.c +13 −6
  8. libavformat/qcp.c +5 −2
  9. libavformat/rmdec.c +9 −6
  10. libavformat/takdec.c +6 −6
  11. libavformat/vividas.c +3 −2
  12. libavformat/vqf.c +7 −8
  13. libavformat/wavdec.c +5 −2
  14. libavformat/wtvdec.c +5 −2
libavformat/argo_brp.c+16−21
@@ -21,6 +21,7 @@ · 20 unmodified lines
2121 */
2222
2323 #include "avformat.h"
24+#include "avio_internal.h"
2425 #include "demux.h"
2526 #include "internal.h"
2627 #include "libavutil/intreadwrite.h"
@@ -139,12 +140,10 @@ static int read_extradata(AVFormatContext *s, const ArgoBRPStreamHeader *hdr, · 112 unmodified lines
139140
140141 av_assert0(bufsz >= size);
141142
142− if ((ret = avio_read(s->pb, buf, size)) < 0)
143+ ret = ffio_read_size(s->pb, buf, size);
144+ if (ret < 0)
143145 return ret;
144146
145− if (ret != size)
146− return AVERROR(EIO);
147−
148147 return 0;
149148 }
150149
@@ -155,10 +154,9 @@ static int argo_brp_read_header(AVFormatContext *s) · 4 unmodified lines
155154 ArgoBRPDemuxContext *brp = s->priv_data;
156155 uint8_t buf[FFMAX(BRP_MIN_BUFFER_SIZE, ASF_MIN_BUFFER_SIZE)];
157156
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)
159159 return ret;
160− else if (ret != BRP_FILE_HEADER_SIZE)
161− return AVERROR(EIO);
162160
163161 brp->fhdr.magic = AV_RL32(buf + 0);
164162 brp->fhdr.num_streams = AV_RL32(buf + 4);
@@ -181,10 +179,9 @@ static int argo_brp_read_header(AVFormatContext *s) · 16 unmodified lines
181179 if (!(st = avformat_new_stream(s, NULL)))
182180 return AVERROR(ENOMEM);
183181
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)
185184 return ret;
186− else if (ret != BRP_STREAM_HEADER_SIZE)
187− return AVERROR(EIO);
188185
189186 hdr->codec_id = AV_RL32(buf + 0);
190187 hdr->id = AV_RL32(buf + 4);
@@ -286,10 +283,9 @@ static int argo_brp_read_header(AVFormatContext *s) · 95 unmodified lines
286283 av_log(s, AV_LOG_TRACE, "Searching %d blocks for BASF...", BRP_BASF_LOOKAHEAD);
287284
288285 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)
290288 return ret;
291− else if (ret != BRP_BLOCK_HEADER_SIZE)
292− return AVERROR(EIO);
293289
294290 blk.stream_id = AV_RL32(buf + 0);
295291 blk.start_ms = AV_RL32(buf + 4);
@@ -313,10 +309,9 @@ static int argo_brp_read_header(AVFormatContext *s) · 17 unmodified lines
313309 if (blk.size < ASF_CHUNK_HEADER_SIZE)
314310 return AVERROR_INVALIDDATA;
315311
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)
317314 return ret;
318− else if (ret != ASF_CHUNK_HEADER_SIZE)
319− return AVERROR(EIO);
320315
321316 ff_argo_asf_parse_chunk_header(&brp->basf.ckhdr, buf);
322317
@@ -358,10 +353,9 @@ static int argo_brp_read_packet(AVFormatContext *s, AVPacket *pkt) · 35 unmodified lines
358353 ArgoASFChunkHeader ckhdr;
359354 int ret;
360355
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)
362358 return ret;
363− else if (ret != BRP_BLOCK_HEADER_SIZE)
364− return AVERROR(EIO);
365359
366360 blk.stream_id = AV_RL32(buf + 0);
367361 blk.start_ms = AV_RL32(buf + 4);
@@ -380,8 +374,9 @@ static int argo_brp_read_packet(AVFormatContext *s, AVPacket *pkt) · 12 unmodified lines
380374 if (blk.size < ASF_CHUNK_HEADER_SIZE)
381375 return AVERROR_INVALIDDATA;
382376
383− if (avio_read(s->pb, buf, ASF_CHUNK_HEADER_SIZE) != ASF_CHUNK_HEADER_SIZE)
384− return AVERROR_INVALIDDATA;
377+ ret = ffio_read_size(s->pb, buf, ASF_CHUNK_HEADER_SIZE);
378+ if (ret < 0)
379+ return ret;
385380
386381 ff_argo_asf_parse_chunk_header(&ckhdr, buf);
387382
libavformat/flacdec.c+2−3
@@ -25,6 +25,7 @@ · 24 unmodified lines
2525 #include "libavcodec/bytestream.h"
2626 #include "libavcodec/flac.h"
2727 #include "avformat.h"
28+#include "avio_internal.h"
2829 #include "demux.h"
2930 #include "flac_picture.h"
3031 #include "internal.h"
@@ -100,11 +101,9 @@ static int flac_read_header(AVFormatContext *s) · 69 unmodified lines
100101 if (!buffer) {
101102 return AVERROR(ENOMEM);
102103 }
103− ret = avio_read(s->pb, buffer, metadata_size);
104+ ret = ffio_read_size(s->pb, buffer, metadata_size);
104105 if (ret < 0) {
105106 RETURN_ERROR(ret);
106− } else if (ret != metadata_size) {
107− RETURN_ERROR(AVERROR_EOF);
108107 }
109108 break;
110109 /* skip metadata block for unsupported types */
libavformat/ilbc.c+5−2
@@ -22,6 +22,7 @@ · 21 unmodified lines
2222 #include "config_components.h"
2323
2424 #include "avformat.h"
25+#include "avio_internal.h"
2526 #include "demux.h"
2627 #include "internal.h"
2728 #include "mux.h"
@@ -60,9 +61,11 @@ static int ilbc_read_header(AVFormatContext *s) · 32 unmodified lines
6061 AVIOContext *pb = s->pb;
6162 AVStream *st;
6263 uint8_t header[9];
64+ int ret;
6365
64− if (avio_read(pb, header, 9) != 9)
65− return AVERROR_INVALIDDATA;
66+ ret = ffio_read_size(pb, header, 9);
67+ if (ret < 0)
68+ return ret;
6669
6770 st = avformat_new_stream(s, NULL);
6871 if (!st)
libavformat/ipmovie.c+5−2
@@ -35,6 +35,7 @@ · 34 unmodified lines
3535 #include "libavutil/channel_layout.h"
3636 #include "libavutil/intreadwrite.h"
3737 #include "avformat.h"
38+#include "avio_internal.h"
3839 #include "demux.h"
3940 #include "internal.h"
4041
@@ -611,11 +612,13 @@ static int ipmovie_read_header(AVFormatContext *s) · 570 unmodified lines
611612 unsigned char chunk_preamble[CHUNK_PREAMBLE_SIZE];
612613 int chunk_type, i;
613614 uint8_t signature_buffer[sizeof(signature)];
615+ int ret;
614616
615617 ipmovie->avf = s;
616618
617− if (avio_read(pb, signature_buffer, sizeof(signature_buffer)) != sizeof(signature_buffer))
618− return AVERROR_INVALIDDATA;
619+ ret = ffio_read_size(pb, signature_buffer, sizeof(signature_buffer));
620+ if (ret < 0)
621+ return ret;
619622 while (memcmp(signature_buffer, signature, sizeof(signature))) {
620623 memmove(signature_buffer, signature_buffer + 1, sizeof(signature_buffer) - 1);
621624 signature_buffer[sizeof(signature_buffer) - 1] = avio_r8(pb);
libavformat/mm.c+7−4
@@ -34,6 +34,7 @@ · 33 unmodified lines
3434 #include "libavutil/channel_layout.h"
3535 #include "libavutil/intreadwrite.h"
3636 #include "avformat.h"
37+#include "avio_internal.h"
3738 #include "demux.h"
3839 #include "internal.h"
3940
@@ -144,8 +145,9 @@ static int read_packet(AVFormatContext *s, · 104 unmodified lines
144145 if (avio_feof(pb))
145146 return AVERROR_EOF;
146147
147− if (avio_read(pb, preamble, MM_PREAMBLE_SIZE) != MM_PREAMBLE_SIZE)
148− return AVERROR(EIO);
148+ ret = ffio_read_size(pb, preamble, MM_PREAMBLE_SIZE);
149+ if (ret < 0)
150+ return ret;
149151
150152 type = AV_RL16(&preamble[0]);
151153 length = AV_RL16(&preamble[2]);
@@ -163,8 +165,9 @@ static int read_packet(AVFormatContext *s, · 11 unmodified lines
163165 if ((ret = av_new_packet(pkt, length + MM_PREAMBLE_SIZE)) < 0)
164166 return ret;
165167 memcpy(pkt->data, preamble, MM_PREAMBLE_SIZE);
166− if (avio_read(pb, pkt->data + MM_PREAMBLE_SIZE, length) != length)
167− return AVERROR(EIO);
168+ ret = ffio_read_size(pb, pkt->data + MM_PREAMBLE_SIZE, length);
169+ if (ret < 0)
170+ return ret;
168171 pkt->size = length + MM_PREAMBLE_SIZE;
169172 pkt->stream_index = 0;
170173 if (type!=MM_TYPE_PALETTE)
libavformat/mpeg.c+3−3
@@ -566,9 +566,9 @@ redo: · 565 unmodified lines
566566 static const unsigned char avs_seqh[4] = { 0, 0, 1, 0xb0 };
567567 unsigned char buf[8];
568568
569− ret = avio_read(s->pb, buf, 8);
570− if (ret != 8)
571− return AVERROR_INVALIDDATA;
569+ ret = ffio_read_size(s->pb, buf, 8);
570+ if (ret < 0)
571+ return ret;
572572 avio_seek(s->pb, -8, SEEK_CUR);
573573 if (!memcmp(buf, avs_seqh, 4) && (buf[6] != 0 || buf[7] != 1))
574574 codec_id = AV_CODEC_ID_CAVS;
libavformat/mxfdec.c+13−6
@@ -62,6 +62,7 @@ · 61 unmodified lines
6262 #include "libavutil/opt.h"
6363 #include "avformat.h"
6464 #include "avlanguage.h"
65+#include "avio_internal.h"
6566 #include "demux.h"
6667 #include "internal.h"
6768 #include "mxf.h"
@@ -659,6 +660,7 @@ static int mxf_decrypt_triplet(AVFormatContext *s, AVPacket *pkt, KLVPacket *klv · 591 unmodified lines
659660 uint64_t plaintext_size;
660661 uint8_t ivec[16];
661662 uint8_t tmpbuf[16];
663+ int ret;
662664 int index;
663665 int body_sid;
664666
@@ -696,8 +698,9 @@ static int mxf_decrypt_triplet(AVFormatContext *s, AVPacket *pkt, KLVPacket *klv · 31 unmodified lines
696698 if (size < 32 || size - 32 < orig_size || (int)orig_size != orig_size)
697699 return AVERROR_INVALIDDATA;
698700 avio_read(pb, ivec, 16);
699− if (avio_read(pb, tmpbuf, 16) != 16)
700− return AVERROR_INVALIDDATA;
701+ ret = ffio_read_size(pb, tmpbuf, 16);
702+ if (ret < 16)
703+ return ret;
701704 if (mxf->aesc)
702705 av_aes_crypt(mxf->aesc, tmpbuf, tmpbuf, 1, ivec, 1);
703706 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
753756 uint64_t footer_partition;
754757 uint32_t nb_essence_containers;
755758 uint64_t this_partition;
759+ int ret;
756760
757761 if (mxf->partitions_count >= INT_MAX / 2)
758762 return AVERROR_INVALIDDATA;
@@ -818,9 +822,10 @@ static int mxf_read_partition_pack(void *arg, AVIOContext *pb, int tag, int size · 59 unmodified lines
818822 if (partition->body_offset < 0)
819823 return AVERROR_INVALIDDATA;
820824
821− if (avio_read(pb, op, sizeof(UID)) != sizeof(UID)) {
825+ ret = ffio_read_size(pb, op, sizeof(UID));
826+ if (ret < 0) {
822827 av_log(mxf->fc, AV_LOG_ERROR, "Failed reading UID\n");
823− return AVERROR_INVALIDDATA;
828+ return ret;
824829 }
825830 nb_essence_containers = avio_rb32(pb);
826831
@@ -1552,12 +1557,14 @@ static int mxf_read_indirect_value(void *arg, AVIOContext *pb, int size) · 725 unmodified lines
15521557 {
15531558 MXFTaggedValue *tagged_value = arg;
15541559 uint8_t key[17];
1560+ int ret;
15551561
15561562 if (size <= 17)
15571563 return 0;
15581564
1559− if (avio_read(pb, key, 17) != 17)
1560− return AVERROR_INVALIDDATA;
1565+ ret = ffio_read_size(pb, key, 17);
1566+ if (ret < 0)
1567+ return ret;
15611568 /* TODO: handle other types of of indirect values */
15621569 if (memcmp(key, mxf_indirect_value_utf16le, 17) == 0) {
15631570 return mxf_read_utf16le_string(pb, size - 17, &tagged_value->value);
libavformat/qcp.c+5−2
@@ -30,6 +30,7 @@ · 29 unmodified lines
3030 #include "libavutil/channel_layout.h"
3131 #include "libavutil/intreadwrite.h"
3232 #include "avformat.h"
33+#include "avio_internal.h"
3334 #include "demux.h"
3435 #include "riff.h"
3536
@@ -94,6 +95,7 @@ static int qcp_read_header(AVFormatContext *s) · 58 unmodified lines
9495 QCPContext *c = s->priv_data;
9596 AVStream *st = avformat_new_stream(s, NULL);
9697 uint8_t buf[16];
98+ int ret;
9799 int i;
98100 unsigned nb_rates;
99101
@@ -105,8 +107,9 @@ static int qcp_read_header(AVFormatContext *s) · 5 unmodified lines
105107
106108 st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
107109 st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
108− if (avio_read(pb, buf, 16) != 16)
109− return AVERROR_INVALIDDATA;
110+ ret = ffio_read_size(pb, buf, 16);
111+ if (ret < 0)
112+ return ret;
110113 if (is_qcelp_13k_guid(buf)) {
111114 st->codecpar->codec_id = AV_CODEC_ID_QCELP;
112115 } else if (!memcmp(buf, guid_evrc, 16)) {
libavformat/rmdec.c+9−6
@@ -188,8 +188,9 @@ static int rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb, · 187 unmodified lines
188188 st->codecpar->ch_layout.nb_channels = avio_rb16(pb);
189189 if (version == 5) {
190190 ast->deint_id = avio_rl32(pb);
191− if (avio_read(pb, buf, 4) != 4)
192− return AVERROR_INVALIDDATA;
191+ ret = ffio_read_size(pb, buf, 4);
192+ if (ret < 0)
193+ return ret;
193194 buf[4] = 0;
194195 } else {
195196 AV_WL32(buf, 0);
@@ -816,10 +817,11 @@ static int rm_assemble_video_frame(AVFormatContext *s, AVIOContext *pb, · 620 unmodified lines
816817 pkt->data[0] = 0;
817818 AV_WL32(pkt->data + 1, 1);
818819 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) {
820822 av_packet_unref(pkt);
821823 av_log(s, AV_LOG_ERROR, "Failed to read %d bytes\n", len);
822− return ret < 0 ? ret : AVERROR(EIO);
824+ return ret;
823825 }
824826 return 0;
825827 }
@@ -856,8 +858,9 @@ static int rm_assemble_video_frame(AVFormatContext *s, AVIOContext *pb, · 30 unmodified lines
856858 av_log(s, AV_LOG_ERROR, "outside videobufsize\n");
857859 return 1;
858860 }
859− if (avio_read(pb, vst->pkt.data + vst->videobufpos, len) != len)
860− return AVERROR(EIO);
861+ ret = ffio_read_size(pb, vst->pkt.data + vst->videobufpos, len);
862+ if (ret < 0)
863+ return ret;
861864 vst->videobufpos += len;
862865 rm->remaining_len-= len;
863866
libavformat/takdec.c+6−6
@@ -96,10 +96,10 @@ static int tak_read_header(AVFormatContext *s) · 95 unmodified lines
9696 memset(buffer + size - 3, 0, AV_INPUT_BUFFER_PADDING_SIZE);
9797
9898 ffio_init_checksum(pb, tak_check_crc, 0xCE04B7U);
99− ret = avio_read(pb, buffer, size - 3);
100− if (ret != size - 3) {
99+ ret = ffio_read_size(pb, buffer, size - 3);
100+ if (ret < 0) {
101101 av_freep(&buffer);
102− return ret < 0 ? ret : AVERROR_INVALIDDATA;
102+ return ret;
103103 }
104104 if (ffio_get_checksum(s->pb) != avio_rb24(pb)) {
105105 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
117117 if (size != 19)
118118 return AVERROR_INVALIDDATA;
119119 ffio_init_checksum(pb, tak_check_crc, 0xCE04B7U);
120− ret = avio_read(pb, md5, 16);
121− if (ret != 16)
122− return ret < 0 ? ret : AVERROR_INVALIDDATA;
120+ ret = ffio_read_size(pb, md5, 16);
121+ if (ret < 0)
122+ return ret;
123123 if (ffio_get_checksum(s->pb) != avio_rb24(pb)) {
124124 av_log(s, AV_LOG_ERROR, "MD5 metadata block CRC error.\n");
125125 if (s->error_recognition & AV_EF_EXPLODE)
libavformat/vividas.c+3−2
@@ -567,8 +567,9 @@ static int viv_read_header(AVFormatContext *s) · 566 unmodified lines
567567 v = avio_r8(pb);
568568 avio_seek(pb, v, SEEK_CUR);
569569
570− if (avio_read(pb, keybuffer, 187) != 187)
571− return AVERROR_INVALIDDATA;
570+ ret = ffio_read_size(pb, keybuffer, 187);
571+ if (ret < 0)
572+ return ret;
572573 key = decode_key(keybuffer);
573574 viv->sb_key = key;
574575
libavformat/vqf.c+7−8
@@ -20,6 +20,7 @@ · 19 unmodified lines
2020 */
2121
2222 #include "avformat.h"
23+#include "avio_internal.h"
2324 #include "demux.h"
2425 #include "internal.h"
2526 #include "libavutil/intreadwrite.h"
@@ -65,10 +66,10 @@ static int add_metadata(AVFormatContext *s, uint32_t tag, · 39 unmodified lines
6566 if (!buf)
6667 return AVERROR(ENOMEM);
6768
68− ret = avio_read(s->pb, buf, len);
69− if (ret < 0 || ret != len) {
69+ ret = ffio_read_size(s->pb, buf, len);
70+ if (ret < 0) {
7071 av_free(buf);
71− return ret < 0 ? ret : AVERROR_INVALIDDATA;
72+ return ret;
7273 }
7374 buf[len] = 0;
7475 AV_WL32(key, tag);
@@ -259,11 +260,9 @@ static int vqf_read_packet(AVFormatContext *s, AVPacket *pkt) · 184 unmodified lines
259260
260261 pkt->data[0] = 8 - c->remaining_bits; // Number of bits to skip
261262 pkt->data[1] = c->last_frame_bits;
262− ret = avio_read(s->pb, pkt->data+2, size);
263−
264− if (ret != size) {
265− return AVERROR(EIO);
266− }
263+ ret = ffio_read_size(s->pb, pkt->data + 2, size);
264+ if (ret < 0)
265+ return ret;
267266
268267 c->last_frame_bits = pkt->data[size+1];
269268 c->remaining_bits = (size << 3) - c->frame_bit_len + c->remaining_bits;
libavformat/wavdec.c+5−2
@@ -872,9 +872,12 @@ static int w64_read_header(AVFormatContext *s) · 871 unmodified lines
872872 WAVDemuxContext *wav = s->priv_data;
873873 AVStream *st;
874874 uint8_t guid[16];
875− int ret;
875+ int ret = ffio_read_size(pb, guid, 16);
876+
877+ if (ret < 0)
878+ return ret;
876879
877− if (avio_read(pb, guid, 16) != 16 || memcmp(guid, ff_w64_guid_riff, 16))
880+ if (memcmp(guid, ff_w64_guid_riff, 16))
878881 return AVERROR_INVALIDDATA;
879882
880883 /* riff + wave + fmt + sizes */
libavformat/wtvdec.c+5−2
@@ -34,6 +34,7 @@ · 33 unmodified lines
3434 #include "libavutil/mem.h"
3535 #include "libavutil/time_internal.h"
3636 #include "avformat.h"
37+#include "avio_internal.h"
3738 #include "demux.h"
3839 #include "internal.h"
3940 #include "wtv.h"
@@ -774,6 +775,7 @@ static int parse_chunks(AVFormatContext *s, int mode, int64_t seekts, int *len_p · 734 unmodified lines
774775 {
775776 WtvContext *wtv = s->priv_data;
776777 AVIOContext *pb = wtv->pb;
778+ int ret;
777779 while (!avio_feof(pb)) {
778780 ff_asf_guid g;
779781 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
846848 }
847849
848850 buf_size = FFMIN(len - consumed, sizeof(buf));
849− if (avio_read(pb, buf, buf_size) != buf_size)
850− return AVERROR_INVALIDDATA;
851+ ret = ffio_read_size(pb, buf, buf_size);
852+ if (ret < 0)
853+ return ret;
851854 consumed += buf_size;
852855 ff_parse_mpeg2_descriptor(s, st, 0, &pbuf, buf + buf_size, NULL, 0, 0, NULL);
853856 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t