From patchwork Sat Aug 3 11:09:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 14211 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 877F2446FD9 for ; Sat, 3 Aug 2019 14:09:57 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 641CC68ACD0; Sat, 3 Aug 2019 14:09:57 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A496C68ACA8 for ; Sat, 3 Aug 2019 14:09:51 +0300 (EEST) X-Originating-IP: 213.47.41.20 Received: from localhost (213-47-41-20.cable.dynamic.surfer.at [213.47.41.20]) (Authenticated sender: michael@niedermayer.cc) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id A594FFF805 for ; Sat, 3 Aug 2019 11:09:50 +0000 (UTC) Date: Sat, 3 Aug 2019 13:09:49 +0200 From: Michael Niedermayer To: FFmpeg development discussions and patches Message-ID: <20190803110949.GQ3219@michaelspb> References: <20190802234957.11098-1-michael@niedermayer.cc> <20190802234957.11098-3-michael@niedermayer.cc> <20190803024332.GA11632@03c6969757591f24d93ff278761a2e57> MIME-Version: 1.0 In-Reply-To: <20190803024332.GA11632@03c6969757591f24d93ff278761a2e57> User-Agent: Mutt/1.5.24 (2015-08-30) Subject: Re: [FFmpeg-devel] [PATCH 3/6] avcodec/pictordec: Optimize picmemset() for single plane full lines 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" On Sat, Aug 03, 2019 at 12:43:32PM +1000, Peter Ross wrote: > On Sat, Aug 03, 2019 at 01:49:54AM +0200, Michael Niedermayer wrote: > > Fixes: Timeout (72sec -> 1sec) > > Fixes: 15512/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_PICTOR_fuzzer-5663942342344704 > > > > Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg > > Signed-off-by: Michael Niedermayer > > --- > > libavcodec/pictordec.c | 16 +++++++++++++++- > > 1 file changed, 15 insertions(+), 1 deletion(-) > > > > diff --git a/libavcodec/pictordec.c b/libavcodec/pictordec.c > > index 2e6fcdca52..5beb03cd5d 100644 > > --- a/libavcodec/pictordec.c > > +++ b/libavcodec/pictordec.c > > @@ -66,6 +66,7 @@ static void picmemset(PicContext *s, AVFrame *frame, unsigned value, int run, > > int xl = *x; > > int yl = *y; > > int planel = *plane; > > + int pixels_per_value = 8/bits_per_plane; > > value <<= shift; > > > > d = frame->data[0] + yl * frame->linesize[0]; > > @@ -74,7 +75,7 @@ static void picmemset(PicContext *s, AVFrame *frame, unsigned value, int run, > > for (j = 8-bits_per_plane; j >= 0; j -= bits_per_plane) { > > d[xl] |= (value >> j) & mask; > > xl += 1; > > - if (xl == s->width) { > > + while (xl == s->width) { > > yl -= 1; > > xl = 0; > > if (yl < 0) { > > @@ -86,6 +87,19 @@ static void picmemset(PicContext *s, AVFrame *frame, unsigned value, int run, > > mask <<= bits_per_plane; > > } > > d = frame->data[0] + yl * frame->linesize[0]; > > + if (s->nb_planes == 1 && > > + run*pixels_per_value >= s->width && > > + pixels_per_value < s->width) { > > + int j; > > + for (j = 8-bits_per_plane; j >= 0; j -= bits_per_plane) { > > suggest naming it 'k' to avoid confusion with earlier for loop. actually, looking at this again, i think we should use the same j, This also now excludes s->width % pixels_per_value != 0 for which i suspect there is no testcase. Ill add support for this in case the fuzzer finds a case that way we then also have a testcase for implementing that corner case. heres the new code: [...] --- a/libavcodec/pictordec.c +++ b/libavcodec/pictordec.c @@ -66,6 +66,7 @@ static void picmemset(PicContext *s, AVFrame *frame, unsigned value, int run, int xl = *x; int yl = *y; int planel = *plane; + int pixels_per_value = 8/bits_per_plane; value <<= shift; d = frame->data[0] + yl * frame->linesize[0]; @@ -74,7 +75,7 @@ static void picmemset(PicContext *s, AVFrame *frame, unsigned value, int run, for (j = 8-bits_per_plane; j >= 0; j -= bits_per_plane) { d[xl] |= (value >> j) & mask; xl += 1; - if (xl == s->width) { + while (xl == s->width) { yl -= 1; xl = 0; if (yl < 0) { @@ -86,6 +87,19 @@ static void picmemset(PicContext *s, AVFrame *frame, unsigned value, int run, mask <<= bits_per_plane; } d = frame->data[0] + yl * frame->linesize[0]; + if (s->nb_planes == 1 && + run*pixels_per_value >= s->width && + pixels_per_value < s->width && + s->width % pixels_per_value == 0 + ) { + for (; xl < pixels_per_value; xl ++) { + j = (j < bits_per_plane ? 8 : j) - bits_per_plane; + d[xl] |= (value >> j) & mask; + } + av_memcpy_backptr(d+xl, pixels_per_value, s->width - xl); + run -= s->width / pixels_per_value; + xl = s->width; + } } } run--;