From patchwork Sun Aug 13 22:15:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 4703 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.46.211 with SMTP id u202csp3597769vsu; Sun, 13 Aug 2017 15:16:12 -0700 (PDT) X-Received: by 10.223.163.16 with SMTP id c16mr16542969wrb.173.1502662572814; Sun, 13 Aug 2017 15:16:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502662572; cv=none; d=google.com; s=arc-20160816; b=RnVdaHzMxAeEksKWokP737YPc/Sp9P9+TZgh/91hju7JOkO6RgMA8ulfb6d4HauUdH myOBQrw8Vb1EUhXMPS7oy9K8jOS1A6XD4Qd0P94+FcURUPbxofJXmqXB4LSILy0NtdWn jgTGTAgdXqoA5jQxQpfQqeiFzE/xPBL965KAfAYkLpSGgke82289pCKGxsp3Z6wc3dJN 07xXbMU65WKb3mNfTNknc7MX/5oNA68fLoZFsskb60z7Acbqtv12Naxlvw81qxAD8Zfs r/2K/Aolvc+iumKUlfdpma/MuejidIfD6prTNFtT+P+q4kia693KTZJrrbLHxmSFa0ej p2xA== 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=ejiiNnH4w/HXiWzyI02cUl9en3Pu9gJ1GHOlMxFB18E=; b=HqzCPYygQcOd/GrmICj+i/d/1RF4yHU5JqLk7Si350l09VFAVwuoFL7sgLKGAsuq+o t3Vmotd+eRLUcDVz+9JP+LxK53fwXKrx7iTVo8z8cGZlxU9C2hkNNRvZpkGp6HIUcQgz u07jG4j4Kv2oAA50sTLHCCnzdt9579UDhZWjoixUyO+ryGprK4hcvgBIJ+0umvfwkZh9 q+yFQdHrJ3xHjeWIeJSsyKxSOK/aXrzBLod/Cnp/0dXmgBdOotkW48Ch6LO1K30W6m3t fPJkUM324bDvevbKRKCGo6LQ8INmb7lqlQgup4hIVZL4EIKqb90v8NtbJkRZ2tPiZqBS IZHg== 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 e1si4660197wrc.491.2017.08.13.15.16.11; Sun, 13 Aug 2017 15:16:12 -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 B11CD689D0E; Mon, 14 Aug 2017 01:16:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe05-1.mx.upcmail.net (vie01a-dmta-pe06-1.mx.upcmail.net [84.116.36.14]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 94854680D22 for ; Mon, 14 Aug 2017 01:15:57 +0300 (EEST) Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe06.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1dh1Au-0007hY-Ej for ffmpeg-devel@ffmpeg.org; Mon, 14 Aug 2017 00:16:00 +0200 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id wmFw1v00H0S5wYM01mFx9X; Mon, 14 Aug 2017 00:15:57 +0200 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Mon, 14 Aug 2017 00:15:54 +0200 Message-Id: <20170813221555.17253-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.13.0 Subject: [FFmpeg-devel] [PATCH 1/2] avcodec/rangecoder: Do not increase the pointer beyond the 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Fixes: undefined behavior Signed-off-by: Michael Niedermayer --- libavcodec/rangecoder.c | 1 + libavcodec/rangecoder.h | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/libavcodec/rangecoder.c b/libavcodec/rangecoder.c index 0bb79c880e..0d53bef076 100644 --- a/libavcodec/rangecoder.c +++ b/libavcodec/rangecoder.c @@ -58,6 +58,7 @@ av_cold void ff_init_range_decoder(RangeCoder *c, const uint8_t *buf, c->low = AV_RB16(c->bytestream); c->bytestream += 2; + c->overread = 0; if (c->low >= 0xFF00) { c->low = 0xFF00; c->bytestream_end = c->bytestream; diff --git a/libavcodec/rangecoder.h b/libavcodec/rangecoder.h index c3e81d0dcb..44af88b8f5 100644 --- a/libavcodec/rangecoder.h +++ b/libavcodec/rangecoder.h @@ -42,6 +42,8 @@ typedef struct RangeCoder { uint8_t *bytestream_start; uint8_t *bytestream; uint8_t *bytestream_end; + int overread; +#define MAX_OVERREAD 2 } RangeCoder; void ff_init_range_encoder(RangeCoder *c, uint8_t *buf, int buf_size); @@ -106,9 +108,11 @@ static inline void refill(RangeCoder *c) if (c->range < 0x100) { c->range <<= 8; c->low <<= 8; - if (c->bytestream < c->bytestream_end) + if (c->bytestream < c->bytestream_end) { c->low += c->bytestream[0]; - c->bytestream++; + c->bytestream++; + } else + c->overread ++; } }