Commit 0572bd1a authored by Alex Agranovsky's avatar Alex Agranovsky Committed by Michael Niedermayer

mpjpeg: probe should require same constraints as packet reader - both proper...

mpjpeg: probe should require same constraints as packet reader - both proper content-type and content-size must be present

return AVPROBE_SCORE_MAX, rather than random positive number on success
Signed-off-by: 's avatarMichael Niedermayer <michael@niedermayer.cc>
parent b65ffa31
...@@ -77,6 +77,8 @@ static int check_content_type(char *line) ...@@ -77,6 +77,8 @@ static int check_content_type(char *line)
return 0; return 0;
} }
static int parse_multipart_header(AVIOContext *pb, void *log_ctx);
static int mpjpeg_read_probe(AVProbeData *p) static int mpjpeg_read_probe(AVProbeData *p)
{ {
AVIOContext *pb; AVIOContext *pb;
...@@ -90,17 +92,7 @@ static int mpjpeg_read_probe(AVProbeData *p) ...@@ -90,17 +92,7 @@ static int mpjpeg_read_probe(AVProbeData *p)
if (!pb) if (!pb)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
while (!pb->eof_reached) { ret = (parse_multipart_header(pb, NULL)>0)?AVPROBE_SCORE_MAX:0;
ret = get_line(pb, line, sizeof(line));
if (ret < 0)
break;
ret = check_content_type(line);
if (!ret) {
ret = AVPROBE_SCORE_MAX;
break;
}
}
av_free(pb); av_free(pb);
...@@ -147,23 +139,23 @@ static int parse_content_length(const char *value) ...@@ -147,23 +139,23 @@ static int parse_content_length(const char *value)
return val; return val;
} }
static int parse_multipart_header(AVFormatContext *s) static int parse_multipart_header(AVIOContext *pb, void *log_ctx)
{ {
char line[128]; char line[128];
int found_content_type = 0; int found_content_type = 0;
int ret, size = -1; int ret, size = -1;
ret = get_line(s->pb, line, sizeof(line)); ret = get_line(pb, line, sizeof(line));
if (ret < 0) if (ret < 0)
return ret; return ret;
if (strncmp(line, "--", 2)) if (strncmp(line, "--", 2))
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
while (!s->pb->eof_reached) { while (!pb->eof_reached) {
char *tag, *value; char *tag, *value;
ret = get_line(s->pb, line, sizeof(line)); ret = get_line(pb, line, sizeof(line));
if (ret < 0) { if (ret < 0) {
if (ret==AVERROR_EOF) if (ret==AVERROR_EOF)
break; break;
...@@ -179,9 +171,12 @@ static int parse_multipart_header(AVFormatContext *s) ...@@ -179,9 +171,12 @@ static int parse_multipart_header(AVFormatContext *s)
if (!av_strcasecmp(tag, "Content-type")) { if (!av_strcasecmp(tag, "Content-type")) {
if (av_strcasecmp(value, "image/jpeg")) { if (av_strcasecmp(value, "image/jpeg")) {
av_log(s, AV_LOG_ERROR, if (log_ctx) {
"Unexpected %s : %s\n", av_log(log_ctx, AV_LOG_ERROR,
tag, value); "Unexpected %s : %s\n",
tag, value);
}
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} else } else
found_content_type = 1; found_content_type = 1;
...@@ -202,7 +197,7 @@ static int parse_multipart_header(AVFormatContext *s) ...@@ -202,7 +197,7 @@ static int parse_multipart_header(AVFormatContext *s)
static int mpjpeg_read_packet(AVFormatContext *s, AVPacket *pkt) static int mpjpeg_read_packet(AVFormatContext *s, AVPacket *pkt)
{ {
int ret; int ret;
int size = parse_multipart_header(s); int size = parse_multipart_header(s->pb, s);
if (size < 0) if (size < 0)
return size; return size;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment