From patchwork Tue Sep 4 00:29:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 10225 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:12c4:0:0:0:0:0 with SMTP id 65-v6csp3266796jap; Mon, 3 Sep 2018 17:30:42 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYfkKN5P9z5xComBRxI+uI/nJHDnA/aKKbahZG9SsyV8myieStd4nscXiGSVy1UJzp8vXYZ X-Received: by 2002:adf:90e9:: with SMTP id i96-v6mr20624088wri.146.1536021042536; Mon, 03 Sep 2018 17:30:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536021042; cv=none; d=google.com; s=arc-20160816; b=izml+l1hthsyxlN7/vOLmO56Bd8kF6W+MeZIGpSouFcvVp2Qa7X3yGTO8sUX/ebOVg xH3SqQAi9VGr0shnjMXf+KduzSE6QGKmr8O+j2OkQYIs5NVTXWqETnQWWH4JxOXPU/Qj 0WM9ujGU3KrSNaylejnYwOa1j2uP1Ml0SAyR2eErWueMe6sR/bwW4tiahwPieOyFTIIs ecPC0U56htX1kED6oRHCFDWVqFGrjEQGKj1uXnkKqhECp6rJuLVOLTsPOD4BrMqH1YuZ qa9SgT4vUcUBknjcPuEjzLZnNlKaKumwYP1D2LmGwx9j8mf2wWI+UvdidO6IleiviE1V qz2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:delivered-to :arc-authentication-results; bh=wS6o68C+9LRAeFIH8BcyiDRzpKgpBhhOD5Kk1eTYa2I=; b=uZ2qiMYGbHy4iirFlgzVBb8aFYMs//P6ttMwjYKHSNdkOJfsoZoll2rqYZlnwAa9qK mCWUnyecG+sgEAHhRQ4HhRU1aWL6guVet2p86j0/kiJH8fiFaHywQRcp4wcZrfKJLvqY WXVdVHrJiWxkKc6ezxuQwzFUV3XxMDo3pqHuiFwsFnbUQ9zFQn163SObUCeFvvBhOTTs kIqpnGQNjfPWZMoLHofQUarPgmPMJ316lRHV1TSuTDGDgEVXPT9a8vwbw9SR+8JvFtmd PKQa15CP0XFQmSG3pbsXVdASWQRDJfbY0se9bAAFxqq9aWBNQd5hMLSyqIWcG2TCNAID Denw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id k65-v6si10453263wma.41.2018.09.03.17.30.41; Mon, 03 Sep 2018 17:30:42 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1D610689C16; Tue, 4 Sep 2018 03:30:33 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-qmta-pe02-2.mx.upcmail.net (vie01a-qmta-pe02-2.mx.upcmail.net [62.179.121.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 42E13689B85 for ; Tue, 4 Sep 2018 03:30:26 +0300 (EEST) Received: from [172.31.218.49] (helo=vie01a-dmta-pe07-1.mx.upcmail.net) by vie01a-pqmta-pe02.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1fwzEm-0006jc-0d for ffmpeg-devel@ffmpeg.org; Tue, 04 Sep 2018 02:30:32 +0200 Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe07.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1fwzEg-0005Y1-4k for ffmpeg-devel@ffmpeg.org; Tue, 04 Sep 2018 02:30:26 +0200 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id XCWF1y00v0S5wYM01CWGhl; Tue, 04 Sep 2018 02:30:17 +0200 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Tue, 4 Sep 2018 02:29:51 +0200 Message-Id: <20180904002951.10741-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.18.0 Subject: [FFmpeg-devel] [PATCH] libavcodec/pnm_parser: do not loose skipped parts in reporting of how much was consumed 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Fixes: Timeout Fixes: 9759/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_PPM_fuzzer-5655277650051072 Fixes: 9753/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_PGMYUV_fuzzer-5764378543521792 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/pnm_parser.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libavcodec/pnm_parser.c b/libavcodec/pnm_parser.c index 4bcd0ddd5d..9bf1fdcece 100644 --- a/libavcodec/pnm_parser.c +++ b/libavcodec/pnm_parser.c @@ -32,6 +32,7 @@ static int pnm_parse(AVCodecParserContext *s, AVCodecContext *avctx, ParseContext *pc = s->priv_data; PNMContext pnmctx; int next; + int skip = 0; for (; pc->overread > 0; pc->overread--) { pc->buffer[pc->index++]= pc->buffer[pc->overread_index++]; @@ -43,8 +44,8 @@ retry: pnmctx.bytestream_end = pc->buffer + pc->index; } else { pnmctx.bytestream_start = - pnmctx.bytestream = (uint8_t *) buf; /* casts avoid warnings */ - pnmctx.bytestream_end = (uint8_t *) buf + buf_size; + pnmctx.bytestream = (uint8_t *) buf + skip; /* casts avoid warnings */ + pnmctx.bytestream_end = (uint8_t *) buf + buf_size - skip; } if (ff_pnm_decode_header(avctx, &pnmctx) < 0) { if (pnmctx.bytestream < pnmctx.bytestream_end) { @@ -52,8 +53,8 @@ retry: pc->index = 0; } else { unsigned step = FFMAX(1, pnmctx.bytestream - pnmctx.bytestream_start); - buf += step; - buf_size -= step; + + skip += step; } goto retry; } @@ -61,9 +62,9 @@ retry: } else if (pnmctx.type < 4) { next = END_NOT_FOUND; } else { - next = pnmctx.bytestream - pnmctx.bytestream_start + next = pnmctx.bytestream - pnmctx.bytestream_start + skip + av_image_get_buffer_size(avctx->pix_fmt, avctx->width, avctx->height, 1); - if (pnmctx.bytestream_start != buf) + if (pnmctx.bytestream_start != buf + skip) next -= pc->index; if (next > buf_size) next = END_NOT_FOUND;