diff --git a/libavformat/mpjpegdec.c b/libavformat/mpjpegdec.c
index b8281fc..e4d76f3 100644
--- a/libavformat/mpjpegdec.c
+++ b/libavformat/mpjpegdec.c
@@ -154,8 +154,11 @@ static int parse_multipart_header(AVFormatContext *s)
     int ret, size = -1;
 
     ret = get_line(s->pb, line, sizeof(line));
-    if (ret < 0)
+    if (ret < 0) {
+        if (ret==AVERROR_EOF)
+            break;
         return ret;
+    }
 
     if (strncmp(line, "--", 2))
         return AVERROR_INVALIDDATA;
