From c276d4be77912f148e4d75e561773574d26960f7 Mon Sep 17 00:00:00 2001
From: Alex Agranovsky <alex@sighthound.com>
Date: Sun, 13 Sep 2015 16:47:54 -0400
Subject: [PATCH] mpjpeg: probe should require same constraints as packet
 reader - both proper content-type and content-size must be present

---
 libavformat/mpjpegdec.c | 32 +++++++++++++-------------------
 1 file changed, 13 insertions(+), 19 deletions(-)

diff --git a/libavformat/mpjpegdec.c b/libavformat/mpjpegdec.c
index 868fab1..5959d70 100644
--- a/libavformat/mpjpegdec.c
+++ b/libavformat/mpjpegdec.c
@@ -103,6 +103,8 @@ static int check_content_type(char *line)
     return 0;
 }
 
+static int parse_multipart_header2(AVIOContext *pb);
+
 static int mpjpeg_read_probe(AVProbeData *p)
 {
     AVIOContext *pb;
@@ -116,17 +118,7 @@ static int mpjpeg_read_probe(AVProbeData *p)
     if (!pb)
         return AVERROR(ENOMEM);
 
-    while (!pb->eof_reached) {
-        ret = get_line(pb, line, sizeof(line));
-        if (ret < 0)
-            break;
-
-        ret = check_content_type(line);
-        if (!ret) {
-            ret = AVPROBE_SCORE_MAX;
-            break;
-        }
-    }
+    ret = parse_multipart_header2(pb);
 
     av_free(pb);
 
@@ -173,23 +165,23 @@ static int parse_content_length(const char *value)
     return val;
 }
 
-static int parse_multipart_header(AVFormatContext *s)
+static int parse_multipart_header2(AVIOContext *pb)
 {
     char line[128];
     int found_content_type = 0;
     int ret, size = -1;
 
-    ret = get_line(s->pb, line, sizeof(line));
+    ret = get_line(pb, line, sizeof(line));
     if (ret < 0)
         return ret;
 
     if (strncmp(line, "--", 2))
         return AVERROR_INVALIDDATA;
 
-    while (!s->pb->eof_reached) {
+    while (!pb->eof_reached) {
         char *tag, *value;
 
-        ret = get_line(s->pb, line, sizeof(line));
+        ret = get_line(pb, line, sizeof(line));
         if (ret < 0) {
             if (ret==AVERROR_EOF)
                 break;
@@ -207,9 +199,6 @@ static int parse_multipart_header(AVFormatContext *s)
 
         if (!av_strcasecmp(tag, "Content-type")) {
             if (av_strcasecmp(value, "image/jpeg")) {
-                av_log(s, AV_LOG_ERROR,
-                       "Unexpected %s : %s\n",
-                       tag, value);
                 return AVERROR_INVALIDDATA;
             } else
                 found_content_type = 1;
@@ -227,11 +216,16 @@ static int parse_multipart_header(AVFormatContext *s)
     return size;
 }
 
+static int parse_multipart_header(AVFormatContext *s)
+{
+    return parse_multipart_header2(s->pb);
+}
+
+
 static int mpjpeg_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
     int ret;
     int size = parse_multipart_header(s);
-
     if (size < 0)
         return size;
 
-- 
2.3.2 (Apple Git-55)

