diff options
author | Alex Converse <alex.converse@gmail.com> | 2011-09-23 16:28:23 -0700 |
---|---|---|
committer | Reinhard Tartler <siretart@tauware.de> | 2012-03-18 17:50:14 +0100 |
commit | 2f62b677cc1ee6002ed953b4515807a170fd51b3 (patch) | |
tree | 5a5edb78abc1946b7cfae9aa335b11c5586952b6 | |
parent | 684f671f2874855d6e9872213097e732bc5cfb18 (diff) | |
download | ffmpeg-2f62b677cc1ee6002ed953b4515807a170fd51b3.tar.gz |
mpegps: Handle buffer exhaustion when reading packets.
(cherry picked from commit 9fba8ebe0acdc28193d37b5e1f4c0d73c589ede2)
Signed-off-by: Anton Khirnov <anton@khirnov.net>
-rw-r--r-- | libavformat/mpeg.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c index 496b9d45f5..9407b3f5b6 100644 --- a/libavformat/mpeg.c +++ b/libavformat/mpeg.c @@ -418,7 +418,7 @@ static int mpegps_read_packet(AVFormatContext *s, { MpegDemuxContext *m = s->priv_data; AVStream *st; - int len, startcode, i, es_type; + int len, startcode, i, es_type, ret; enum CodecID codec_id = CODEC_ID_NONE; enum AVMediaType type; int64_t pts, dts, dummy_pos; //dummy_pos is needed for the index building to work @@ -562,7 +562,13 @@ static int mpegps_read_packet(AVFormatContext *s, return AVERROR(EINVAL); } av_new_packet(pkt, len); - avio_read(s->pb, pkt->data, pkt->size); + ret = avio_read(s->pb, pkt->data, pkt->size); + if (ret < 0) { + pkt->size = 0; + } else if (ret < pkt->size) { + pkt->size = ret; + memset(pkt->data + ret, 0, FF_INPUT_BUFFER_PADDING_SIZE); + } pkt->pts = pts; pkt->dts = dts; pkt->pos = dummy_pos; @@ -571,7 +577,7 @@ static int mpegps_read_packet(AVFormatContext *s, pkt->stream_index, pkt->pts / 90000.0, pkt->dts / 90000.0, pkt->size); - return 0; + return (ret < 0) ? ret : 0; } static int64_t mpegps_read_dts(AVFormatContext *s, int stream_index, |