Amended: one of the new blocks ended up in a wrong location. libavformat/mpjpegdec.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/libavformat/mpjpegdec.c b/libavformat/mpjpegdec.c index 8413ae7..1661b9d 100644 --- a/libavformat/mpjpegdec.c +++ b/libavformat/mpjpegdec.c @@ -43,11 +43,20 @@ static int get_line(AVIOContext *pb, char *line, int line_size) static int split_tag_value(char **tag, char **value, char *line) { char *p = line; + int foundData = 0; - while (*p != '\0' && *p != ':') + *tag = NULL; + *value = NULL; + + + while (*p != '\0' && *p != ':') { + if (!av_isspace(*p)) { + foundData = 1; + } p++; + } if (*p != ':') - return AVERROR_INVALIDDATA; + return foundData?AVERROR_INVALIDDATA:0; *p = '\0'; *tag = line; @@ -67,7 +76,7 @@ static int check_content_type(char *line) char *tag, *value; int ret = split_tag_value(&tag, &value, line); - if (ret < 0) + if (ret < 0 || tag == NULL || value == NULL) return ret; if (av_strcasecmp(tag, "Content-type") || @@ -173,7 +182,9 @@ static int parse_multipart_header(AVFormatContext *s) ret = split_tag_value(&tag, &value, line); if (ret < 0) return ret; - + if (value==NULL || tag==NULL) + break; + if (!av_strcasecmp(tag, "Content-type")) { if (av_strcasecmp(value, "image/jpeg")) { av_log(s, AV_LOG_ERROR, -- Alex Agranovsky Sighthound, Inc www.sighthound.com On September 12, 2015 at 4:50:54 PM, Alex Agranovsky (a...@sighthound.com) wrote: libavformat/mpjpegdec.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/libavformat/mpjpegdec.c b/libavformat/mpjpegdec.c index 8413ae7..c1ca508 100644 --- a/libavformat/mpjpegdec.c +++ b/libavformat/mpjpegdec.c @@ -43,11 +43,22 @@ static int get_line(AVIOContext *pb, char *line, int line_size) static int split_tag_value(char **tag, char **value, char *line) { char *p = line; + int foundData = 0; - while (*p != '\0' && *p != ':') + *tag = NULL; + *value = NULL; + + + while (*p != '\0' && *p != ':') { + if (!av_isspace(*p)) { + foundData = 1; + } p++; - if (*p != ':') - return AVERROR_INVALIDDATA; + } + if (*p != ':') { + /* don't fail the parser if dealing with an empty line */ + return foundData?AVERROR_INVALIDDATA:0; + } *p = '\0'; *tag = line; @@ -166,12 +177,15 @@ static int parse_multipart_header(AVFormatContext *s) ret = get_line(s->pb, line, sizeof(line)); if (ret < 0) break; + /* CRLF terminates a sequence of MIME headers */ + if (value==NULL || tag==NULL) + break; if (line[0] == '\0') break; ret = split_tag_value(&tag, &value, line); - if (ret < 0) + if (ret < 0 || tag == NULL || value == NULL) return ret; if (!av_strcasecmp(tag, "Content-type")) { -- Alex Agranovsky Sighthound, Inc www.sighthound.com _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel