From patchwork Sun Sep 4 18:58:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carl Eugen Hoyos X-Patchwork-Id: 417 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.134 with SMTP id o128csp2404734vsd; Sun, 4 Sep 2016 11:58:57 -0700 (PDT) X-Received: by 10.194.69.226 with SMTP id h2mr602809wju.36.1473015537230; Sun, 04 Sep 2016 11:58:57 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id fy6si21458443wjb.192.2016.09.04.11.58.55; Sun, 04 Sep 2016 11:58:57 -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 37895689E33; Sun, 4 Sep 2016 21:58:45 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe01-3.mx.upcmail.net (vie01a-dmta-pe01-3.mx.upcmail.net [62.179.121.156]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8BE91689E1D for ; Sun, 4 Sep 2016 21:58:38 +0300 (EEST) Received: from [172.31.216.44] (helo=vie01a-pemc-psmtp-pe02) by vie01a-dmta-pe01.mx.upcmail.net with esmtp (Exim 4.87) (envelope-from ) id 1bgccw-0003QL-CF for ffmpeg-devel@ffmpeg.org; Sun, 04 Sep 2016 20:58:46 +0200 Received: from [192.168.1.3] ([80.110.104.164]) by vie01a-pemc-psmtp-pe02 with SMTP @ mailcloud.upcmail.net id fWyk1t00j3YpwW801Wym92; Sun, 04 Sep 2016 20:58:46 +0200 X-SourceIP: 80.110.104.164 From: Carl Eugen Hoyos To: FFmpeg development discussions and patches Date: Sun, 4 Sep 2016 20:58:44 +0200 User-Agent: KMail/1.9.10 MIME-Version: 1.0 Message-Id: <201609042058.44816.cehoyos@ag.or.at> Subject: [FFmpeg-devel] [PATCH]lavc/pnmdec: Do not fail by default for truncated pbm files 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" Hi! Some scanner - scannersoftware combination (HP_Officejet_Pro_X476dn_MFP - sane) truncates trailing zeros in pbm files and FreeImage (a library used in free and proprietary image software) reads such files. Attached patch copies this behaviour and fixes ticket #5795. Please comment, Carl Eugen From af00c56b38b28e07bbba46031472da41300a8cf1 Mon Sep 17 00:00:00 2001 From: Carl Eugen Hoyos Date: Sun, 4 Sep 2016 20:52:28 +0200 Subject: [PATCH] lavc/pnmdec: Do not abort by default for truncated pbm files. Fixes ticket #5795. --- libavcodec/pnmdec.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libavcodec/pnmdec.c b/libavcodec/pnmdec.c index d4261a4..0b7a0f6 100644 --- a/libavcodec/pnmdec.c +++ b/libavcodec/pnmdec.c @@ -124,8 +124,12 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, do_read: ptr = p->data[0]; linesize = p->linesize[0]; - if (s->bytestream + n * avctx->height > s->bytestream_end) - return AVERROR_INVALIDDATA; + if (s->bytestream + n * avctx->height > s->bytestream_end) { + av_log(avctx, AV_LOG_ERROR, + "Invalid truncated file\n"); + if (avctx->strict_std_compliance >= FF_COMPLIANCE_STRICT) + return AVERROR_INVALIDDATA; + } if(s->type < 4 || (is_mono && s->type==7)){ for (i=0; iheight; i++) { PutBitContext pb; @@ -159,6 +163,8 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, } }else{ for (i = 0; i < avctx->height; i++) { + if (s->bytestream + n > s->bytestream_end) + continue; if (!upgrade) samplecpy(ptr, s->bytestream, n, s->maxval); else if (upgrade == 1) {