avformat: Use ffio_read_size where appropriate

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2021-08-06 22:47:22 +02:00
parent dccd1d2a58
commit d1ac645636
8 changed files with 27 additions and 31 deletions

View File

@ -21,6 +21,7 @@
#include "libavutil/intreadwrite.h"
#include "avformat.h"
#include "avio_internal.h"
#include "internal.h"
typedef struct AAXColumn {
@ -215,12 +216,9 @@ static int aax_read_header(AVFormatContext *s)
if (ret64 < 0)
return ret;
ret = avio_read(pb, a->string_table, a->strings_size);
if (ret != a->strings_size) {
if (ret < 0)
return ret;
return AVERROR(EIO);
}
ret = ffio_read_size(pb, a->string_table, a->strings_size);
if (ret < 0)
return ret;
for (int c = 0; c < a->columns; c++) {
int64_t data_offset = 0;

View File

@ -19,6 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avformat.h"
#include "avio_internal.h"
#include "riff.h"
#include "internal.h"
#include "libavcodec/get_bits.h"
@ -126,12 +127,10 @@ static int read_packet(AVFormatContext *s,
if(s->streams[0]->codecpar->sample_rate==4400 && !ctx->second_packet)
{
ret = avio_read(pb, ctx->audio_buffer, frame_size);
ret = ffio_read_size(pb, ctx->audio_buffer, frame_size);
if(ret<0)
return ret;
if(ret!=frame_size)
return AVERROR(EIO);
pkt->data[0]=ctx->audio_buffer[11];
pkt->data[1]=ctx->audio_buffer[0];
@ -165,12 +164,10 @@ static int read_packet(AVFormatContext *s,
}
else // 8000 Hz
{
ret = avio_read(pb, ctx->audio_buffer, frame_size);
ret = ffio_read_size(pb, ctx->audio_buffer, frame_size);
if(ret<0)
return ret;
if(ret!=frame_size)
return AVERROR(EIO);
pkt->data[0]=ctx->audio_buffer[5];
pkt->data[1]=ctx->audio_buffer[0];

View File

@ -22,6 +22,7 @@
#include "libavutil/channel_layout.h"
#include "avformat.h"
#include "avio_internal.h"
#include "internal.h"
#include "rawenc.h"
#include "libavutil/intreadwrite.h"
@ -57,10 +58,8 @@ static int kvag_read_header(AVFormatContext *s)
if (!(st = avformat_new_stream(s, NULL)))
return AVERROR(ENOMEM);
if ((ret = avio_read(s->pb, buf, KVAG_HEADER_SIZE)) < 0)
if ((ret = ffio_read_size(s->pb, buf, KVAG_HEADER_SIZE)) < 0)
return ret;
else if (ret != KVAG_HEADER_SIZE)
return AVERROR(EIO);
hdr.magic = AV_RL32(buf + 0);
hdr.data_size = AV_RL32(buf + 4);

View File

@ -24,6 +24,7 @@
#include "libavutil/intreadwrite.h"
#include "libavutil/intfloat.h"
#include "avformat.h"
#include "avio_internal.h"
#include "internal.h"
#include "riff.h"
@ -258,9 +259,9 @@ static int nuv_packet(AVFormatContext *s, AVPacket *pkt)
int copyhdrsize = ctx->rtjpg_video ? HDRSIZE : 0;
uint64_t pos = avio_tell(pb);
ret = avio_read(pb, hdr, HDRSIZE);
if (ret < HDRSIZE)
return ret < 0 ? ret : AVERROR(EIO);
ret = ffio_read_size(pb, hdr, HDRSIZE);
if (ret < 0)
return ret;
frametype = hdr[0];
size = PKTSIZE(AV_RL32(&hdr[8]));

View File

@ -20,6 +20,7 @@
*/
#include "avformat.h"
#include "avio_internal.h"
#include "internal.h"
#include "mpeg.h"
@ -147,9 +148,9 @@ recover:
goto recover;
}
ret = avio_read(pb, pes_header_data, pes_header_data_length);
if (ret != pes_header_data_length)
return ret < 0 ? ret : AVERROR_INVALIDDATA;
ret = ffio_read_size(pb, pes_header_data, pes_header_data_length);
if (ret < 0)
return ret;
length -= 9 + pes_header_data_length;
pes_packet_length -= 3 + pes_header_data_length;

View File

@ -32,10 +32,10 @@ int ff_get_guid(AVIOContext *s, ff_asf_guid *g)
{
int ret;
av_assert0(sizeof(*g) == 16); //compiler will optimize this out
ret = avio_read(s, *g, sizeof(*g));
if (ret < (int)sizeof(*g)) {
ret = ffio_read_size(s, *g, sizeof(*g));
if (ret < 0) {
memset(*g, 0, sizeof(*g));
return ret < 0 ? ret : AVERROR_INVALIDDATA;
return ret;
}
return 0;
}

View File

@ -3285,12 +3285,12 @@ int ff_get_extradata(AVFormatContext *s, AVCodecParameters *par, AVIOContext *pb
int ret = ff_alloc_extradata(par, size);
if (ret < 0)
return ret;
ret = avio_read(pb, par->extradata, size);
if (ret != size) {
ret = ffio_read_size(pb, par->extradata, size);
if (ret < 0) {
av_freep(&par->extradata);
par->extradata_size = 0;
av_log(s, AV_LOG_ERROR, "Failed to read extradata of size %d\n", size);
return ret < 0 ? ret : AVERROR_INVALIDDATA;
return ret;
}
return ret;

View File

@ -241,8 +241,8 @@ static inline int wav_parse_bext_string(AVFormatContext *s, const char *key,
int ret;
av_assert0(length < sizeof(temp));
if ((ret = avio_read(s->pb, temp, length)) != length)
return ret < 0 ? ret : AVERROR_INVALIDDATA;
if ((ret = ffio_read_size(s->pb, temp, length)) < 0)
return ret;
temp[length] = 0;
@ -311,9 +311,9 @@ static int wav_parse_bext_tag(AVFormatContext *s, int64_t size)
if (!(coding_history = av_malloc(size + 1)))
return AVERROR(ENOMEM);
if ((ret = avio_read(s->pb, coding_history, size)) != size) {
if ((ret = ffio_read_size(s->pb, coding_history, size)) < 0) {
av_free(coding_history);
return ret < 0 ? ret : AVERROR_INVALIDDATA;
return ret;
}
coding_history[size] = 0;