From patchwork Wed Nov 9 20:05:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Cadhalpun X-Patchwork-Id: 1365 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.90.1 with SMTP id o1csp478476vsb; Wed, 9 Nov 2016 12:05:30 -0800 (PST) X-Received: by 10.194.175.163 with SMTP id cb3mr1267864wjc.174.1478721930901; Wed, 09 Nov 2016 12:05:30 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id c74si24063555wme.33.2016.11.09.12.05.28; Wed, 09 Nov 2016 12:05:30 -0800 (PST) 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; dkim=neutral (body hash did not verify) header.i=@googlemail.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; dmarc=fail (p=QUARANTINE dis=NONE) header.from=googlemail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 16D49689E13; Wed, 9 Nov 2016 22:05:23 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 199CD689D78 for ; Wed, 9 Nov 2016 22:05:16 +0200 (EET) Received: by mail-wm0-f68.google.com with SMTP id a20so20674448wme.2 for ; Wed, 09 Nov 2016 12:05:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=from:subject:to:references:message-id:date:user-agent:mime-version :in-reply-to; bh=qIP9CI0i/xtq+XDfMcV7D+PUnKa6TFXYwX2nXSQWCm4=; b=nOCWd3XGZNkezTw82wgOQLarC9phkdgBoKkPa841V3nHvZBgU9dtXbuq4BU7gVFHv3 gfuYnqRz0rbUno3OX7gjxy50VZwb2YPTXdngwcHSqiCURTuQvR+smGw2RS2tLVPa/LMf rXQgN6zXd5Kg5aTA4kwphn9xepqM4dyGu6bbpyhACayT9M6z63xaJncpYw/O/7J1Fq0N rru+uMtF58s8I4huTqDk8XSSkV9piIAIvWa8W2lJfuUvaMCLuR3yty4VMDr0qXppWwND oWcHBXDj7xe3UGNs4TffIPm1gkScpegqbN0UG1EJbUVku5GgqYb9gs622OJpR2ZrIIeS Drfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:subject:to:references:message-id:date :user-agent:mime-version:in-reply-to; bh=qIP9CI0i/xtq+XDfMcV7D+PUnKa6TFXYwX2nXSQWCm4=; b=cyDFltcI5Kftg0EtXEuxQX+oggbeGJyMh25pBEAHaSOADNLLMQumPBO5klpDhuO4ZN d6F4ygc4veXRlZZJrOZPTP3cJiscBHdzOvO6ZQVbWXS3SrlBM40m4MQOB5m72pXz610H w7J+JvVKOC+oluHSdeIPcsslEc/htfMxsAt+oKzGDga0vdrxn2lS36jSRYq9/2EKi9JB 8zMGVilCYmAXx3zz/kFlYC9rP3oRc76A82KnUtFHlhiVCwVUCIJi07Gu+WfvTRF3drNP 5JNMbYz6wvrt7xMnSKaTnywrrg7ZmL/rK9DObARR/miwdgDmbHPRgPonu0av5aUq+yYf GrOQ== X-Gm-Message-State: ABUngvesheDYedKnWlEDK2qteZSu7jTYwT/eZTlGUGt/fqDA+pMDUOIW8cES+WjjKB2kKw== X-Received: by 10.194.157.3 with SMTP id wi3mr1270218wjb.0.1478721918873; Wed, 09 Nov 2016 12:05:18 -0800 (PST) Received: from [192.168.2.21] (p5B072193.dip0.t-ipconnect.de. [91.7.33.147]) by smtp.googlemail.com with ESMTPSA id jt8sm1346058wjc.33.2016.11.09.12.05.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Nov 2016 12:05:18 -0800 (PST) From: Andreas Cadhalpun X-Google-Original-From: Andreas Cadhalpun To: ffmpeg-devel@ffmpeg.org References: <665e0d12-f81d-3e6a-6f4a-2feccf1b20ec@googlemail.com> <20161109101023.GD4602@nb4> Message-ID: <6880ed2d-64e0-3a28-9f67-06d05cb68f14@googlemail.com> Date: Wed, 9 Nov 2016 21:05:17 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.4.0 MIME-Version: 1.0 In-Reply-To: <20161109101023.GD4602@nb4> Subject: Re: [FFmpeg-devel] [PATCH] pnmdec: make sure v is capped by maxval 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 09.11.2016 11:10, Michael Niedermayer wrote: > On Wed, Nov 09, 2016 at 01:11:29AM +0100, Andreas Cadhalpun wrote: >> Otherwise put_bits can be called with a value that doesn't fit in the >> sample_len, causing an assertion failure. >> --- >> libavcodec/pnmdec.c | 4 ++++ >> 1 file changed, 4 insertions(+) >> >> diff --git a/libavcodec/pnmdec.c b/libavcodec/pnmdec.c >> index ca97cc3..0381ea6 100644 >> --- a/libavcodec/pnmdec.c >> +++ b/libavcodec/pnmdec.c >> @@ -145,6 +145,10 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, >> /* read a sequence of digits */ >> do { >> v = 10*v + c; >> + if (v > s->maxval) { >> + av_log(avctx, AV_LOG_ERROR, "value %d larger than maxval %d\n", v, s->maxval); >> + return AVERROR_INVALIDDATA; >> + } > > indention is a bit noisy Fixed. > i think it can overflow if maxval is large, I've added an explicit check for v < 0, which should catch that. > it would be faster to check outside the loop However, such a check could pass if v overflowed so much that it's in the valid range again, so I'd rather not do that. Updated patch is attached. Best regards, Andreas From 7e9dcbde04ad95fc93ac2f0e91d734c8187c8d2b Mon Sep 17 00:00:00 2001 From: Andreas Cadhalpun Date: Wed, 9 Nov 2016 01:09:35 +0100 Subject: [PATCH] pnmdec: make sure v is capped by maxval Otherwise put_bits can be called with a value that doesn't fit in the sample_len, causing an assertion failure. --- libavcodec/pnmdec.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libavcodec/pnmdec.c b/libavcodec/pnmdec.c index ca97cc3..8961310 100644 --- a/libavcodec/pnmdec.c +++ b/libavcodec/pnmdec.c @@ -145,6 +145,10 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, /* read a sequence of digits */ do { v = 10*v + c; + if (v < 0 || v > s->maxval) { + av_log(avctx, AV_LOG_ERROR, "value %d larger than maxval %d (or overflown)\n", v, s->maxval); + return AVERROR_INVALIDDATA; + } c = (*s->bytestream++) - '0'; } while (c <= 9); } -- 2.10.2