From patchwork Tue Sep 29 21:10:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 22663 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 D7348449925 for ; Wed, 30 Sep 2020 00:10:47 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C450E68B5BB; Wed, 30 Sep 2020 00:10:47 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1AC5C68B31D for ; Wed, 30 Sep 2020 00:10:39 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 8C139E45AC; Tue, 29 Sep 2020 23:10:39 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8FtLcNmafC8E; Tue, 29 Sep 2020 23:10:38 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 9D5A2E45E4; Tue, 29 Sep 2020 23:10:37 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Tue, 29 Sep 2020 23:10:17 +0200 Message-Id: <20200929211021.25030-5-cus@passwd.hu> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200929211021.25030-1-cus@passwd.hu> References: <20200929211021.25030-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/9] avformat/mpjpegdec: make sure we seek back to the ensured buffer 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: Marton Balint Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" It was possible for the old code to seek back before the most recently read data if start of a new multipart was across read boundaries. Now we read some small sections multiple times to avoid this, but that is OK. Signed-off-by: Marton Balint --- libavformat/mpjpegdec.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libavformat/mpjpegdec.c b/libavformat/mpjpegdec.c index df2880412d..5fe00fd162 100644 --- a/libavformat/mpjpegdec.c +++ b/libavformat/mpjpegdec.c @@ -328,18 +328,18 @@ static int mpjpeg_read_packet(AVFormatContext *s, AVPacket *pkt) ret = av_get_packet(s->pb, pkt, size); } else { /* no size was given -- we read until the next boundary or end-of-file */ - int remaining = 0, len; + int len; const int read_chunk = 2048; pkt->pos = avio_tell(s->pb); - while ((ret = ffio_ensure_seekback(s->pb, read_chunk - remaining)) >= 0 && /* we may need to return as much as all we've read back to the buffer */ - (ret = av_append_packet(s->pb, pkt, read_chunk - remaining)) >= 0) { + while ((ret = ffio_ensure_seekback(s->pb, read_chunk)) >= 0 && /* we may need to return as much as all we've read back to the buffer */ + (ret = av_append_packet(s->pb, pkt, read_chunk)) >= 0) { /* scan the new data */ char *start; - len = ret + remaining; + len = ret; start = pkt->data + pkt->size - len; do { if (!memcmp(start, mpjpeg->searchstr, mpjpeg->searchstr_len)) { @@ -351,7 +351,8 @@ static int mpjpeg_read_packet(AVFormatContext *s, AVPacket *pkt) len--; start++; } while (len >= mpjpeg->searchstr_len); - remaining = len; + avio_seek(s->pb, -len, SEEK_CUR); + pkt->size -= len; } /* error or EOF occurred */