diff --git a/libavformat/4xm.c b/libavformat/4xm.c index a6101a92ec..aea9226984 100644 --- a/libavformat/4xm.c +++ b/libavformat/4xm.c @@ -322,8 +322,10 @@ static int fourxm_read_packet(AVFormatContext *s, case cfr2_TAG: /* allocate 8 more bytes than 'size' to account for fourcc * and size */ - if (size + 8 < size || av_new_packet(pkt, size + 8)) - return AVERROR(EIO); + if (size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE - 8) + return AVERROR_INVALIDDATA; + if ((ret = av_new_packet(pkt, size + 8)) < 0) + return ret; pkt->stream_index = fourxm->video_stream_index; pkt->pts = fourxm->video_pts; pkt->pos = avio_tell(s->pb); @@ -347,7 +349,7 @@ static int fourxm_read_packet(AVFormatContext *s, fourxm->tracks[track_number].channels > 0) { ret = av_get_packet(s->pb, pkt, size); if (ret < 0) - return AVERROR(EIO); + return ret; pkt->stream_index = fourxm->tracks[track_number].stream_index; pkt->pts = fourxm->tracks[track_number].audio_pts; diff --git a/libavformat/flic.c b/libavformat/flic.c index 615d6b25c5..d2a5cf995c 100644 --- a/libavformat/flic.c +++ b/libavformat/flic.c @@ -215,10 +215,9 @@ static int flic_read_packet(AVFormatContext *s, magic = AV_RL16(&preamble[4]); if (((magic == FLIC_CHUNK_MAGIC_1) || (magic == FLIC_CHUNK_MAGIC_2)) && size > FLIC_PREAMBLE_SIZE) { - if (av_new_packet(pkt, size)) { - ret = AVERROR(EIO); - break; - } + if ((ret = av_new_packet(pkt, size)) < 0) + return ret; + pkt->stream_index = flic->video_stream_index; pkt->pts = flic->frame_number++; pkt->pos = avio_tell(pb); @@ -231,10 +230,8 @@ static int flic_read_packet(AVFormatContext *s, } packet_read = 1; } else if (magic == FLIC_TFTD_CHUNK_AUDIO) { - if (av_new_packet(pkt, size)) { - ret = AVERROR(EIO); - break; - } + if ((ret = av_new_packet(pkt, size)) < 0) + return ret; /* skip useless 10B sub-header (yes, it's not accounted for in the chunk header) */ avio_skip(pb, 10); diff --git a/libavformat/idroqdec.c b/libavformat/idroqdec.c index 1db4cce6f0..16aa2a146e 100644 --- a/libavformat/idroqdec.c +++ b/libavformat/idroqdec.c @@ -205,8 +205,9 @@ static int roq_read_packet(AVFormatContext *s, } /* load up the packet */ - if (av_new_packet(pkt, chunk_size + RoQ_CHUNK_PREAMBLE_SIZE)) - return AVERROR(EIO); + ret = av_new_packet(pkt, chunk_size + RoQ_CHUNK_PREAMBLE_SIZE); + if (ret < 0) + return ret; /* copy over preamble */ memcpy(pkt->data, preamble, RoQ_CHUNK_PREAMBLE_SIZE); diff --git a/libavformat/psxstr.c b/libavformat/psxstr.c index ddc17e35d2..678b9f90ac 100644 --- a/libavformat/psxstr.c +++ b/libavformat/psxstr.c @@ -160,7 +160,7 @@ static int str_read_packet(AVFormatContext *s, AVIOContext *pb = s->pb; StrDemuxContext *str = s->priv_data; unsigned char sector[RAW_CD_SECTOR_SIZE]; - int channel; + int channel, ret; AVPacket *pkt; AVStream *st; @@ -213,8 +213,9 @@ static int str_read_packet(AVFormatContext *s, if(pkt->data) av_log(s, AV_LOG_ERROR, "mismatching sector_count\n"); av_packet_unref(pkt); - if (av_new_packet(pkt, sector_count*VIDEO_DATA_CHUNK_SIZE)) - return AVERROR(EIO); + ret = av_new_packet(pkt, sector_count * VIDEO_DATA_CHUNK_SIZE); + if (ret < 0) + return ret; memset(pkt->data, 0, sector_count*VIDEO_DATA_CHUNK_SIZE); pkt->pos= avio_tell(pb) - RAW_CD_SECTOR_SIZE; @@ -267,8 +268,8 @@ static int str_read_packet(AVFormatContext *s, st->start_time = 0; } pkt = ret_pkt; - if (av_new_packet(pkt, 2304)) - return AVERROR(EIO); + if ((ret = av_new_packet(pkt, 2304)) < 0) + return ret; memcpy(pkt->data,sector+24,2304); pkt->stream_index = diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c index 3c4b97d49f..a36e693ab2 100644 --- a/libavformat/rmdec.c +++ b/libavformat/rmdec.c @@ -781,8 +781,8 @@ static int rm_assemble_video_frame(AVFormatContext *s, AVIOContext *pb, return -1; } rm->remaining_len -= len; - if(av_new_packet(pkt, len + 9) < 0) - return AVERROR(EIO); + if ((ret = av_new_packet(pkt, len + 9)) < 0) + return ret; pkt->data[0] = 0; AV_WL32(pkt->data + 1, 1); AV_WL32(pkt->data + 5, 0); @@ -804,8 +804,8 @@ static int rm_assemble_video_frame(AVFormatContext *s, AVIOContext *pb, vst->slices = ((hdr & 0x3F) << 1) + 1; vst->videobufsize = len2 + 8*vst->slices + 1; av_packet_unref(&vst->pkt); //FIXME this should be output. - if(av_new_packet(&vst->pkt, vst->videobufsize) < 0) - return AVERROR(ENOMEM); + if ((ret = av_new_packet(&vst->pkt, vst->videobufsize)) < 0) + return ret; memset(vst->pkt.data, 0, vst->pkt.size); vst->videobufpos = 8*vst->slices + 1; vst->cur_slice = 0; diff --git a/libavformat/vqf.c b/libavformat/vqf.c index b43725b3c1..2916ee64fa 100644 --- a/libavformat/vqf.c +++ b/libavformat/vqf.c @@ -237,8 +237,8 @@ static int vqf_read_packet(AVFormatContext *s, AVPacket *pkt) int ret; int size = (c->frame_bit_len - c->remaining_bits + 7)>>3; - if (av_new_packet(pkt, size+2) < 0) - return AVERROR(EIO); + if ((ret = av_new_packet(pkt, size + 2)) < 0) + return ret; pkt->pos = avio_tell(s->pb); pkt->stream_index = 0;