From patchwork Fri Jan 24 10:33:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jai Luthra X-Patchwork-Id: 17503 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id EAB8544B5D2 for ; Fri, 24 Jan 2020 12:41:29 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D337968B042; Fri, 24 Jan 2020 12:41:29 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f65.google.com (mail-pj1-f65.google.com [209.85.216.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EAFDA68AFF9 for ; Fri, 24 Jan 2020 12:41:22 +0200 (EET) Received: by mail-pj1-f65.google.com with SMTP id bg7so896651pjb.5 for ; Fri, 24 Jan 2020 02:41:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jailuthra-in.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=JsnrYMTabxJB3Nr86qIxfJ4xA8MkTKBnp/2UhxLESqI=; b=fKYfBF1MSgtOVxMMGIwWhBnWqeDtAiKHtRl7ZSOg0zjGorI+fKmyznTQT7iQ0n8sQc 5/79MizZOxA9bvaChnFVtkR4q+6PnhCR5bfgjluhvgwU8opIDonhIgUwJOha9/UoS3qs kojQIWNjC0tjx1ooqjtSrV73dlRfAUGOeydq975c6MpvRI29ktbiQ+A/X1FgLx9FbmL+ 9JQQlkmslcxKs52pOCHzVCsq52uMZx0R6i2bVryBl3ojFO0sUmftMQdw9X2/LKimufdD g9JVdcSkuU7kzIa8XbacVIZvwc77WuCwd7/0Bv2EG4Rm+BLGbGPyt88tW5dTON6QB5z+ gBWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JsnrYMTabxJB3Nr86qIxfJ4xA8MkTKBnp/2UhxLESqI=; b=qBpEw0efE42ikddqV8hZJ9rUwDHr6bUxov5KyaB4XJr+MiEahkCGLCymPImg0MMMeN t5zpuE5ibepyw/tJTy/ADnRCQQMHN74zAtptxfurpDPl12QW7/KwHstoiSXbSu9y1Y8B 5XCPkRFsBUhDS/yRTBvkMZKsNmF2cSN4WwKrNUZGmTftr7I0mKGdY7xh0GMFLxdlAltz xBSxVGvg0uS8BXBPYO5DjsDigVQN8lpJ2NUfPFiCguZT9slMEYIiiCEP0HYmN1qjQjrg PMXC4j8FSxWBy0z73iEebgnqssJIIH5zsWMbn//3bnNNY69ZolzA+mefg6WTpFtL9NEV yrMQ== X-Gm-Message-State: APjAAAUBNG6FC34pPyKHOVM8M53AhYqygGFBF/SsaMwjsTmEdqoLgPbe /TteXRLBX6CK5UcEUliO4FTleZ6NdxQ= X-Google-Smtp-Source: APXvYqwvqxGa8t3+azcU9ITK9xnmvPaG8n4oTryv56ZR18nRiX311AXSt6iUSix4sX1i+twMiXqMmw== X-Received: by 2002:a17:902:be0a:: with SMTP id r10mr2894297pls.118.1579862029024; Fri, 24 Jan 2020 02:33:49 -0800 (PST) Received: from localhost.localdomain ([49.207.55.142]) by smtp.googlemail.com with ESMTPSA id j125sm5471274pfg.160.2020.01.24.02.33.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2020 02:33:48 -0800 (PST) From: Jai Luthra To: ffmpeg-devel@ffmpeg.org Date: Fri, 24 Jan 2020 16:03:32 +0530 Message-Id: <20200124103334.110855-4-me@jailuthra.in> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200124103334.110855-1-me@jailuthra.in> References: <20200124103334.110855-1-me@jailuthra.in> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/5] mlpenc: prevent negative lsb_bits lshift 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" Fixes Coverity CID 1396239. Signed-off-by: Jai Luthra --- libavcodec/mlpenc.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libavcodec/mlpenc.c b/libavcodec/mlpenc.c index 1cee38c82f..41030f6f07 100644 --- a/libavcodec/mlpenc.c +++ b/libavcodec/mlpenc.c @@ -1,6 +1,7 @@ /** * MLP encoder * Copyright (c) 2008 Ramiro Polla + * Copyright (c) 2016-2019 Jai Luthra * * This file is part of FFmpeg. * @@ -1562,7 +1563,7 @@ static void no_codebook_bits_offset(MLPEncodeContext *ctx, BestOffset *bo) { DecodingParams *dp = ctx->cur_decoding_params; - int32_t unsign; + int32_t unsign = 0; int lsb_bits; min -= offset; @@ -1572,7 +1573,8 @@ static void no_codebook_bits_offset(MLPEncodeContext *ctx, lsb_bits += !!lsb_bits; - unsign = 1 << (lsb_bits - 1); + if (lsb_bits > 0) + unsign = 1 << (lsb_bits - 1); bo->offset = offset; bo->lsb_bits = lsb_bits; @@ -1591,7 +1593,7 @@ static void no_codebook_bits(MLPEncodeContext *ctx, { DecodingParams *dp = ctx->cur_decoding_params; int16_t offset; - int32_t unsign; + int32_t unsign = 0; uint32_t diff; int lsb_bits; @@ -1607,7 +1609,8 @@ static void no_codebook_bits(MLPEncodeContext *ctx, lsb_bits = number_sbits(diff) - 1; - unsign = 1 << (lsb_bits - 1); + if (lsb_bits > 0) + unsign = 1 << (lsb_bits - 1); /* If all samples are the same (lsb_bits == 0), offset must be * adjusted because of sign_shift. */