From patchwork Wed Apr 1 16:00:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Bouron X-Patchwork-Id: 18572 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 8668544AF50 for ; Wed, 1 Apr 2020 19:01:16 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5B8B868AA48; Wed, 1 Apr 2020 19:01:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0158668925C for ; Wed, 1 Apr 2020 19:01:09 +0300 (EEST) Received: by mail-wm1-f46.google.com with SMTP id c195so3845217wme.1 for ; Wed, 01 Apr 2020 09:01:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=yDSwGTEQGxkivUliuUO8CmUObvZLGUQ/n/bWCtm+lI4=; b=GWWALA6kjLCvhwK4nA0G76FUfJYOwJNOjituXWyNnVqpMt90rD/bQwDlIXC1cltNTD N3lgEs/SGlcqjysM6c8zmvImyPlkFsU0M7Jimu3i6tV/aYbKBx5TLjBPtMYqJJ6u0GzB qluNAWBlXqKdEKj1KuBkwH16/blsK2AIieZkt718MGws65QdGHhPqMQHFyBxwlU1HvcP kje4DEeYYN216iZCNJqwq51US6K+iInc5wJ4vIxIDx1KH1qaXQKWNe/MpoT+H9BysxDK MpmrALFtNvIPW0ocvdId9HqNYBEjxbw7UlPvh67Mb8ReHgzOn0MNs4R0JoE1V52TDvab JvRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=yDSwGTEQGxkivUliuUO8CmUObvZLGUQ/n/bWCtm+lI4=; b=O2E7XcIuqjq/S6PbjRUY+8Uzrn61b108oDvX6d2VJ3QAYOOiZrPGDPNvuu84jCDIFs /4Ui/Z0WRQhA0hMyxFESI9tZ5oiEjkGVj8H3tPB/onfMpTIFpIk7zukyuD/UrDTmKZCZ IoAO547GR950YE8xaUyytw04jPGG04hvygY6UMsWyMyCBJya54d3Y/BDRQO2ZDu5uMKd IQl09WwDY7uXqAbEPx3tTq0eWkWXViPYVapeuJggTYFjahE8hmc/nw6z+08u8h2bdtzB 3mgYYyly7DX6WZufXFGFrHZH6HrFUPpY0NHN1OJUHmFpkGsFuaiJp9CXZne28EQZqZo8 WNLw== X-Gm-Message-State: AGi0PuZM3UA6zswuNxsPygMccaRrVfJSUX/gmeLGs667rM7X5DBRv2wZ USCYUahBy8PSY1YUfs4Fg2PvtPyt X-Google-Smtp-Source: APiQypK8ivkJzVnaN3KMkMDfsHJFSFDhIyD15EL7Se7rpctW0orThMkV+faMyOnsOlj/MeIMGH3llw== X-Received: by 2002:a7b:cd07:: with SMTP id f7mr5007817wmj.30.1585756869008; Wed, 01 Apr 2020 09:01:09 -0700 (PDT) Received: from localhost.localdomain (lfbn-idf2-1-500-105.w86-246.abo.wanadoo.fr. [86.246.201.105]) by smtp.gmail.com with ESMTPSA id r17sm3420716wrx.46.2020.04.01.09.01.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2020 09:01:08 -0700 (PDT) From: Matthieu Bouron To: ffmpeg-devel@ffmpeg.org Date: Wed, 1 Apr 2020 18:00:41 +0200 Message-Id: <20200401160041.595923-1-matthieu.bouron@gmail.com> X-Mailer: git-send-email 2.26.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/img2dec: return immediately in jpeg_probe() when EOI is found X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Matthieu Bouron Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Fixes probing of JPEG files containing MPF metadata appended at the end of the file. The MPF metadata chunk can contains multiple JPEG images (thumbnails) which makes the jpeg_probe fails (return 0) because it finds a SOI marker after EOI. --- This patch fixes probing of JPEG files containing MPF metadata [1] appended at the end of the file. Such files can be produced by GoPro camera (which produces JPEG files with MPF metadata). You can find a sample here: https://0x5c.me/gopro_jpg_mpf_probe_fail To reproduce the issue using ffmpeg master: wget https://0x5c.me/gopro_jpg_mpf_probe_fail ./ffmpeg -formatprobesize 5000000 -i gopro_jpg_mpf_probe_fail I removed intentionally the jpeg extension from the filename so the image2 demuxer is not used. Current ffmpeg master won't still be able to decode this file because of a "regression" introduced by ec3d8a0e6945fe015d16cd98a1e7dbb4be815c15 on the mjpeg_parser. The jpeg_pipe demuxer outputs partial chunks of the jpeg file that the mjpeg decoder can't handle (it needs the whole data). Before ec3d8a0e6945fe015d16cd98a1e7dbb4be815c15, the mjpeg_parser was outputting a complete frame. If the parser is correct as is, another way to fix this issue whould be to add AVSTREAM_PARSE_HEADERS to the need_parsing flags from the jpeg_pipe demuxer, ie: --- a/libavformat/img2dec.c +++ b/libavformat/img2dec.c @@ -209,7 +209,7 @@ int ff_img_read_header(AVFormatContext *s1) s->is_pipe = 0; else { s->is_pipe = 1; - st->need_parsing = AVSTREAM_PARSE_FULL; + st->need_parsing = AVSTREAM_PARSE_FULL | AVSTREAM_PARSE_HEADERS; Settings AVSTREAM_PARSE_HEADERS makes avformat requests complete frames from the parser in libavformat/utils.c What do you think ? [1] https://exiftool.org/TagNames/MPF.html --- libavformat/img2dec.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c index 93cd51c1932..decd8023e02 100644 --- a/libavformat/img2dec.c +++ b/libavformat/img2dec.c @@ -773,9 +773,7 @@ static int jpeg_probe(const AVProbeData *p) case EOI: if (state != SOS) return 0; - state = EOI; - break; - case DHT: + return AVPROBE_SCORE_EXTENSION + 1; case DQT: case APP0: case APP1: @@ -803,8 +801,6 @@ static int jpeg_probe(const AVProbeData *p) } } - if (state == EOI) - return AVPROBE_SCORE_EXTENSION + 1; if (state == SOS) return AVPROBE_SCORE_EXTENSION / 2; return AVPROBE_SCORE_EXTENSION / 8;