From patchwork Wed Jul 26 22:01:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 4467 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.1.76 with SMTP id 73csp1272638vsb; Wed, 26 Jul 2017 15:01:43 -0700 (PDT) X-Received: by 10.223.176.73 with SMTP id g9mr1773748wra.108.1501106503816; Wed, 26 Jul 2017 15:01:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501106503; cv=none; d=google.com; s=arc-20160816; b=bBpxoJn9h7YZe41pLr63/vuzZfz3xLxDIooyqHOREYh2XsGs+UIp8w+XYkrYf/pfsM 5p3rXlnAE+ue39waLZ4N0mV4KOGq8Wg59YdLyMNfyi9YUAW9+SOOasWNcFRa4uUNde4x UgZY1TL/bR1f5gA+YM8hyLmIYKHvAXPA8yB2exeyHhmVTAuop38HrMYRqqtkoUcfNzCP 3sUmNoxC5uSQfWKIw/YnXRAGNKd3/Q+N4AoVquAvTCVAvk9MSWAlKtSHgOziz8CCWgnM ByGCpqo7ivas/ZQGDjzwtRt26jpMHAFE4yzquneD75vBvV5JrgDYuO+VvCll9K/GbNld RJcw== 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=yIQiBMpNKS0Kl6r9Am0nDwcC4R14NLuF0IAO17zuxX8=; b=sl5tUvZrB2ZY/hF4L7OlHf3pL8JiwB6sLqOqyK9+DmM/YLxKL7VmqzPe8MjKnz3e0+ HXM36LDY5iGXQzhin4sTldz6gwa9vfAod/jeMmasXBczH4tSJ3IrnQ+jK2zp9a56CXq4 pp6wIRRETMsbFhPHAocOKYZkfvFlPWqY8NqbuEsCjVNhA/ciMuMIyIVVqQPlo8QRCvHE jnt/GcpfxqHyxy3fgSy3DLqN7y1alae5D1NF4XsE80rUPomi1eUg+A2/OogHIQ3G2YX9 FfRhubesvDxy2Nr2IMDoDFUaTS+OmQUGYLErsLen7EBmRsaD7mjoO+7bKVRZXe+tBo8D urWg== 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 y191si639779wmy.175.2017.07.26.15.01.38; Wed, 26 Jul 2017 15:01:43 -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 726C2689AF7; Thu, 27 Jul 2017 01:01:34 +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 12F65689889 for ; Thu, 27 Jul 2017 01:01:28 +0300 (EEST) Received: from [172.31.218.35] (helo=vie01a-dmta-pe02-2.mx.upcmail.net) by vie01a-pqmta-pe02.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1daUMy-00074C-3x for ffmpeg-devel@ffmpeg.org; Thu, 27 Jul 2017 00:01:28 +0200 Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe02.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1daUMs-0007qO-Ej for ffmpeg-devel@ffmpeg.org; Thu, 27 Jul 2017 00:01:22 +0200 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id pa1J1v00c0S5wYM01a1K6k; Thu, 27 Jul 2017 00:01:19 +0200 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Thu, 27 Jul 2017 00:01:17 +0200 Message-Id: <20170726220117.23142-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.13.0 Subject: [FFmpeg-devel] [PATCH] avcodec/pixlet: Simplify nbits computation 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 multiple integer overflows Fixes: runtime error: signed integer overflow: 1 + 2147483647 cannot be represented in type 'int' Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/pixlet.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/pixlet.c b/libavcodec/pixlet.c index 0e541a9ccb..a9661d3ab6 100644 --- a/libavcodec/pixlet.c +++ b/libavcodec/pixlet.c @@ -206,8 +206,8 @@ static int read_high_coeffs(AVCodecContext *avctx, uint8_t *src, int16_t *dst, i if ((ret = init_get_bits8(b, src, bytestream2_get_bytes_left(&ctx->gb))) < 0) return ret; - if ((a >= 0) + (a ^ (a >> 31)) - (a >> 31) != 1) { - nbits = 33 - ff_clz((a >= 0) + (a ^ (a >> 31)) - (a >> 31) - 1); + if (a ^ (a >> 31)) { + nbits = 33 - ff_clz(a ^ (a >> 31)); if (nbits > 16) return AVERROR_INVALIDDATA; } else {