[FFmpeg-cvslog] lavf: do basic sanity checking on muxed packets
Anton Khirnov
git at videolan.org
Tue Feb 4 15:23:22 CET 2014
ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Mon Jan 20 14:10:01 2014 +0100| [7b03b65bf0d02519c86750d2da33f413e11cf0c6] | committer: Anton Khirnov
lavf: do basic sanity checking on muxed packets
Reject packets for non-existing or attachment streams.
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7b03b65bf0d02519c86750d2da33f413e11cf0c6
---
libavformat/mux.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/libavformat/mux.c b/libavformat/mux.c
index 505ed2e..24c4932 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -429,10 +429,33 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
return ret;
}
+static int check_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ if (!pkt)
+ return 0;
+
+ if (pkt->stream_index < 0 || pkt->stream_index >= s->nb_streams) {
+ av_log(s, AV_LOG_ERROR, "Invalid packet stream index: %d\n",
+ pkt->stream_index);
+ return AVERROR(EINVAL);
+ }
+
+ if (s->streams[pkt->stream_index]->codec->codec_type == AVMEDIA_TYPE_ATTACHMENT) {
+ av_log(s, AV_LOG_ERROR, "Received a packet for an attachment stream.\n");
+ return AVERROR(EINVAL);
+ }
+
+ return 0;
+}
+
int av_write_frame(AVFormatContext *s, AVPacket *pkt)
{
int ret;
+ ret = check_packet(s, pkt);
+ if (ret < 0)
+ return ret;
+
if (!pkt) {
if (s->oformat->flags & AVFMT_ALLOW_FLUSH)
return s->oformat->write_packet(s, pkt);
@@ -560,6 +583,10 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
{
int ret, flush = 0;
+ ret = check_packet(s, pkt);
+ if (ret < 0)
+ return ret;
+
if (pkt) {
AVStream *st = s->streams[pkt->stream_index];
More information about the ffmpeg-cvslog
mailing list