siff: simplify code by using ffio_limit()

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2011-12-19 19:23:56 +01:00
parent 1dcce49e10
commit b08a742526

View File

@ -22,6 +22,7 @@
#include "libavutil/intreadwrite.h" #include "libavutil/intreadwrite.h"
#include "avformat.h" #include "avformat.h"
#include "internal.h" #include "internal.h"
#include "avio_internal.h"
enum SIFFTags{ enum SIFFTags{
TAG_SIFF = MKTAG('S', 'I', 'F', 'F'), TAG_SIFF = MKTAG('S', 'I', 'F', 'F'),
@ -201,18 +202,16 @@ static int siff_read_packet(AVFormatContext *s, AVPacket *pkt)
} }
if (!c->curstrm){ if (!c->curstrm){
int64_t fsize= avio_size(s->pb); size = c->pktsize - c->sndsize - c->gmcsize - 2;
size = c->pktsize - c->sndsize; size = ffio_limit(s->pb, size);
if(fsize>0) if(size < 0 || c->pktsize < c->sndsize)
size= FFMIN(size, fsize - avio_tell(s->pb) + c->gmcsize + 3);
if(size < 2 + c->gmcsize || c->pktsize < c->sndsize)
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
if (av_new_packet(pkt, size) < 0) if (av_new_packet(pkt, size + c->gmcsize + 2) < 0)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
AV_WL16(pkt->data, c->flags); AV_WL16(pkt->data, c->flags);
if (c->gmcsize) if (c->gmcsize)
memcpy(pkt->data + 2, c->gmc, c->gmcsize); memcpy(pkt->data + 2, c->gmc, c->gmcsize);
avio_read(s->pb, pkt->data + 2 + c->gmcsize, size - c->gmcsize - 2); avio_read(s->pb, pkt->data + 2 + c->gmcsize, size);
pkt->stream_index = 0; pkt->stream_index = 0;
c->curstrm = -1; c->curstrm = -1;
}else{ }else{