@@ -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;
@@ -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);
@@ -230,10 +229,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);
@@ -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);
@@ -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 =
@@ -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;
@@ -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;
This commit improves returned error codes by forwarding error codes. In some instances, the hardcoded returned error codes made no sense at all: The normal error code for failure of av_new_packet() is AVERROR(ENOMEM), yet there were instances where AVERROR(EIO) was returned. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> --- libavformat/4xm.c | 8 +++++--- libavformat/flic.c | 13 +++++-------- libavformat/idroqdec.c | 5 +++-- libavformat/psxstr.c | 11 ++++++----- libavformat/rmdec.c | 8 ++++---- libavformat/vqf.c | 4 ++-- 6 files changed, 25 insertions(+), 24 deletions(-)