From patchwork Fri Jan 24 10:33:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jai Luthra X-Patchwork-Id: 17501 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 9E1D644AB81 for ; Fri, 24 Jan 2020 12:33:54 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6559768AFC3; Fri, 24 Jan 2020 12:33:54 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 36403688369 for ; Fri, 24 Jan 2020 12:33:48 +0200 (EET) Received: by mail-pf1-f178.google.com with SMTP id x185so888294pfc.5 for ; Fri, 24 Jan 2020 02:33:48 -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=CWxLWien2lRLsdLYXbPlNmckaDQIh7+KfpF8SwT58tA=; b=CslE2f1y6vzFyzHzoUSiwd+W1GheS7BGQ3/bbMbExeAATGbcZ65ADt5RShQdpYjM/Z SVqgdKMs1f2uQlL6rF3oieWffKNORkqFe7I3F9nY8BOvLVNHzemdCodBsccRlrQYYbHy j71O0L0yexzBp0dCFPKlVcLoiG3kRmuXAhFvRGOQxcGgSec6J1JLcVudJg63d+MMue3n z+YRtyJ9Bv4lDdH8bSbcorMn1Khdl4hlmmwV6cIJbpyS7eIZK75tWwRFGDvHnmv0op1z NuqxOZ3eBsiZLWmxoPkDPbQrBeggPm5JWe5jwwTO0wkVgJKYcs3kzkPwYcCFFRS2SrCA juyA== 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=CWxLWien2lRLsdLYXbPlNmckaDQIh7+KfpF8SwT58tA=; b=qFLenmG7efWYZmed1DkQX6D+5x82yVtNsYAF/Y3hV4Zqys1ac62WhG7MQf5e/9/jOO bhl2tP+5147vuZT2ia6dHwF+349XCXxqgLeDceE+r6M51MrvB7Z3yBo388Xm88Qjv6bW hbLgNJvlBdknMHrogW7sAgURGXTuqLu2v0S5GZuceZAjH2/neqZY7B1wqKUyiwwfgFZf +VDpg1lEmgv0okAiaQ4BLWh+DdiajLadEJ/8kTlDdb1L97Pma2nydu4aMQwoM3qWYG1d qTrKCIMNiWIf9U+q59OggUHpgkkoFc4nhKvSM1xwoI016HNTkilGUt+f/I8dXVxJsRXp WaFw== X-Gm-Message-State: APjAAAWU7CfP2gEjDkBeRx3ceIWAq9FbObGDsi3lc9DlLGyaDloNpBC8 buInNhV6jXtcPvQBgsL3oS6Wtvbr/x0= X-Google-Smtp-Source: APXvYqyjli6QpUrRiL3C3g1iBcgfWJer0r3OECdxas9DkVeCqxECsM8H9VFBluGj/fm9mJQiBa0EZA== X-Received: by 2002:aa7:8695:: with SMTP id d21mr2679153pfo.199.1579862025982; Fri, 24 Jan 2020 02:33:45 -0800 (PST) Received: from localhost.localdomain ([49.207.55.142]) by smtp.googlemail.com with ESMTPSA id j125sm5471274pfg.160.2020.01.24.02.33.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2020 02:33:45 -0800 (PST) From: Jai Luthra To: ffmpeg-devel@ffmpeg.org Date: Fri, 24 Jan 2020 16:03:30 +0530 Message-Id: <20200124103334.110855-2-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 1/5] mlpenc: fix lossless check error in number_sbits 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" we need two bits instead of one bit to represent -1 in bitstream Signed-off-by: Jai Luthra --- libavcodec/mlpenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/mlpenc.c b/libavcodec/mlpenc.c index deb171645c..f4948451f1 100644 --- a/libavcodec/mlpenc.c +++ b/libavcodec/mlpenc.c @@ -466,7 +466,7 @@ static void default_decoding_params(MLPEncodeContext *ctx, */ static int inline number_sbits(int number) { - if (number < 0) + if (number < -1) number++; return av_log2(FFABS(number)) + 1 + !!number; From patchwork Fri Jan 24 10:33:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jai Luthra X-Patchwork-Id: 17506 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 6B75F448F4D for ; Fri, 24 Jan 2020 13:03:06 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4499368AE91; Fri, 24 Jan 2020 13:03:06 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C291068A764 for ; Fri, 24 Jan 2020 13:02:59 +0200 (EET) Received: by mail-pg1-f194.google.com with SMTP id x8so832971pgk.8 for ; Fri, 24 Jan 2020 03:02:59 -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=ykHunujTnewngmlMEpAQ/zkcm5eGL7IbB1Yq+iCDj+M=; b=yWhmr8/c/5cWmVHl9nbqUX+bL5Hg3yxVuy8F5QgifMLEbq3Yiu/EMic95K8fC7Ikrw O2jDvBQC15NV4ekAp3IvI/Z852iNtScKDKS3V1oMT+qWIEVwp//euoNH0pIPb8iFfb1E WcoGt3X5v2n20BrIn+Z1DleTMtHcRBT0BO4NJ09/63qI9YI8Wt1+Lzt5FWZnU4C2+GE7 3xeQJfctAbw4kWtuVy+KabuD3Ar5Lxjzp7z2Mm20KvZJS7cE2a5+aYrLczzlJE4g+IbH vl0C9Lyvy2AXAgs1oxb+jGJ5sdyYn2t9OTPyNDH/P2HmY/EuORAhhUyNpUdlsH5db1fW roxA== 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=ykHunujTnewngmlMEpAQ/zkcm5eGL7IbB1Yq+iCDj+M=; b=h3bS9lcX2MHShI+Un/7tzGJyyIHgWKfaq9gYolHkHrgom6PiRTKktblugDBQKU1qFI Ipm2HNDSVRvpODl2j/dtUOOUtd9x6crUHTKlkyK7vMuanwnpbvdesCC1x63BVwPOKh50 bwfM4T56C4lZ73cO2gIV6MXva8CixjrbK0phDLsoXOfgxi5PlfpiNfSWH6t0hHN8EbQG zjGgCpR/g7a8pz3F6L/OSTk6XLlnTvpF6F4avyV2UAUV3qzvTYR34i1zus6PRThrPl+7 +qjIR/PGeabp1mlBfnyG5BeOm/HLcAOg04i8pNfavSnqw359uVjNfvE21e42wu0tAmXC bWRQ== X-Gm-Message-State: APjAAAWhLWbKmZ72Msg/SZ6s1hmvKrwPrIvMNTEKBrXh0/UCdb75OTPW zQdQGd9KhH1gesU1A9BVPpF/CHOhDsY= X-Google-Smtp-Source: APXvYqxEKA4nXMkMd1noQ0LB4VnlxXrqdnUkh3iYNc0uCZoZoyu+W7vmp9waAlqEl9DBUhstpU7yBw== X-Received: by 2002:a17:902:8495:: with SMTP id c21mr2919887plo.279.1579862027559; Fri, 24 Jan 2020 02:33:47 -0800 (PST) Received: from localhost.localdomain ([49.207.55.142]) by smtp.googlemail.com with ESMTPSA id j125sm5471274pfg.160.2020.01.24.02.33.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2020 02:33:47 -0800 (PST) From: Jai Luthra To: ffmpeg-devel@ffmpeg.org Date: Fri, 24 Jan 2020 16:03:31 +0530 Message-Id: <20200124103334.110855-3-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 2/5] mlpenc: fix huff offset calculation 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" huff offset wasn't always within the bounds before, which lead to corrupt encoding that didn't always trigger lossless check failures Signed-off-by: Jai Luthra --- libavcodec/mlpenc.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/libavcodec/mlpenc.c b/libavcodec/mlpenc.c index f4948451f1..1cee38c82f 100644 --- a/libavcodec/mlpenc.c +++ b/libavcodec/mlpenc.c @@ -1699,7 +1699,7 @@ static inline void codebook_bits(MLPEncodeContext *ctx, offset_min = FFMAX(min, HUFF_OFFSET_MIN); offset_max = FFMIN(max, HUFF_OFFSET_MAX); - for (;;) { + while (offset <= offset_max && offset >= offset_min) { BestOffset temp_bo; codebook_bits_offset(ctx, channel, codebook, @@ -1718,12 +1718,8 @@ static inline void codebook_bits(MLPEncodeContext *ctx, if (direction) { offset = temp_bo.max + 1; - if (offset > offset_max) - break; } else { offset = temp_bo.min - 1; - if (offset < offset_min) - break; } } } 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. */ From patchwork Fri Jan 24 10:33:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jai Luthra X-Patchwork-Id: 17504 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 DA3EC44B5D2 for ; Fri, 24 Jan 2020 12:41:30 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C1FEE68B0A5; Fri, 24 Jan 2020 12:41:30 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 40B2368AF07 for ; Fri, 24 Jan 2020 12:41:23 +0200 (EET) Received: by mail-pg1-f196.google.com with SMTP id q127so819209pga.4 for ; Fri, 24 Jan 2020 02:41:23 -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=epmLjV/ELk5tNqXa8sLT+7ONW1xY14ldT6KpRlIUkIs=; b=PezV1oJPIpuXmJhySkhzevYsU6a7tshq1gY0GPstYJMzbruowIRkMrCxlxV/i7vRkk oxuxfD7EcMjFIuDSibx/Z3Z+thIVDQi3INFnk0Kt/UouL68eurPX1mMUxG/mXZV+F++c sRuK1fCsYdNkHouO8BUPx836oYxjwhVFvBsXudw3i6lh+hCP7aiWVY2TUfS/VZhFdr3t xQqo0tr6gc3cTJH8KrdyJGHIqBc42QoGKicTx/lJXQ6cCe0Du+fGDESWG7lz3LDbZoHu lSNaKUrBooRV5lAVHA2STYHXhlJUqCiZet8UdSSl7toZh7D0LTD2wqozhYuQ6RnR9QE4 mPYA== 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=epmLjV/ELk5tNqXa8sLT+7ONW1xY14ldT6KpRlIUkIs=; b=o5yQHMg7ZME9yKGxeHPaZ3/DDTyeIk4R2knRaLiHpJuR/jLZ5eN7fwj19/XLPa1Yhq gqmToTGt5DRodu+RdzEmmHyfDUHqf44c6QmLeouGh7aNg8jPyMBzROlcz5yEYFCn1g79 6IqJfo52eAg3NYIM6XDc9BGuViUSc9HGmtl1WaUQ4xddfAG7vRmXAIF2fYhzfp5++nK9 a6+zbG2iQIuEW0fGbRbGp4E9uqV7gEm/2XKCuOh4ReNLZ4FCmHyCy5eHLjmw8oVnY65U NMQOXRp6LdFetYK9QzPsDRmSjNA2aPU8fU7ZJNXVDzuwS/ITnki8XfhHqva8qSfaRdGN wvIA== X-Gm-Message-State: APjAAAUoMM0UlTU/ugsbccvNFf1I05d5Zb3DssF6XK6AbGTsqtZMUQQs hazU842eb2wVOumVGCsi5mMjVe/zi1M= X-Google-Smtp-Source: APXvYqxtPtKnJPXqd4OkMGPZ8/lJf9FX6DfmASdZS3iIVz3XnV/EteXeynNV3iyFI/id/ftGGALw4A== X-Received: by 2002:a63:484b:: with SMTP id x11mr3403095pgk.148.1579862030492; Fri, 24 Jan 2020 02:33:50 -0800 (PST) Received: from localhost.localdomain ([49.207.55.142]) by smtp.googlemail.com with ESMTPSA id j125sm5471274pfg.160.2020.01.24.02.33.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2020 02:33:50 -0800 (PST) From: Jai Luthra To: ffmpeg-devel@ffmpeg.org Date: Fri, 24 Jan 2020 16:03:33 +0530 Message-Id: <20200124103334.110855-5-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 4/5] mlpenc: improve lpc filtering 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" * fix a possible memory leak (apply_filter returned before freeing) * use apply_filters in process_major_frame * revert back to checking bounds with 24 bitdepth, as huff offset takes care of it Signed-off-by: Jai Luthra --- libavcodec/mlpenc.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/libavcodec/mlpenc.c b/libavcodec/mlpenc.c index 41030f6f07..0e7a9b7640 100644 --- a/libavcodec/mlpenc.c +++ b/libavcodec/mlpenc.c @@ -1799,20 +1799,20 @@ static void determine_bits(MLPEncodeContext *ctx) /** Applies the filter to the current samples, and saves the residual back * into the samples buffer. If the filter is too bad and overflows the - * maximum amount of bits allowed (16 or 24), the samples buffer is left as is and + * maximum amount of bits allowed (24), the samples buffer is left as is and * the function returns -1. */ static int apply_filter(MLPEncodeContext *ctx, unsigned int channel) { FilterParams *fp[NUM_FILTERS] = { &ctx->cur_channel_params[channel].filter_params[FIR], &ctx->cur_channel_params[channel].filter_params[IIR], }; - int32_t *filter_state_buffer[NUM_FILTERS]; + int32_t *filter_state_buffer[NUM_FILTERS] = { NULL }; int32_t mask = MSB_MASK(ctx->cur_decoding_params->quant_step_size[channel]); int32_t *sample_buffer = ctx->sample_buffer + channel; unsigned int number_of_samples = ctx->number_of_samples; unsigned int filter_shift = fp[FIR]->shift; int filter; - int i; + int i, ret = 0; for (i = 0; i < NUM_FILTERS; i++) { unsigned int size = ctx->number_of_samples; @@ -1835,7 +1835,7 @@ static int apply_filter(MLPEncodeContext *ctx, unsigned int channel) int32_t sample = *sample_buffer; unsigned int order; int64_t accum = 0; - int32_t residual; + int64_t residual; for (filter = 0; filter < NUM_FILTERS; filter++) { int32_t *fcoeff = ctx->cur_channel_params[channel].coeff[filter]; @@ -1847,11 +1847,13 @@ static int apply_filter(MLPEncodeContext *ctx, unsigned int channel) accum >>= filter_shift; residual = sample - (accum & mask); - if (residual < SAMPLE_MIN(ctx->wordlength) || residual > SAMPLE_MAX(ctx->wordlength)) - return -1; + if (residual < SAMPLE_MIN(24) || residual > SAMPLE_MAX(24)) { + ret = -1; + goto free_and_return; + } filter_state_buffer[FIR][i] = sample; - filter_state_buffer[IIR][i] = residual; + filter_state_buffer[IIR][i] = (int32_t) residual; sample_buffer += ctx->num_channels; } @@ -1863,11 +1865,12 @@ static int apply_filter(MLPEncodeContext *ctx, unsigned int channel) sample_buffer += ctx->num_channels; } +free_and_return: for (i = 0; i < NUM_FILTERS; i++) { av_freep(&filter_state_buffer[i]); } - return 0; + return ret; } static void apply_filters(MLPEncodeContext *ctx) @@ -2198,9 +2201,6 @@ static void process_major_frame(MLPEncodeContext *ctx) ctx->number_of_samples = ctx->major_frame_size; for (substr = 0; substr < ctx->num_substreams; substr++) { - RestartHeader *rh = ctx->cur_restart_header; - unsigned int channel; - ctx->cur_restart_header = &ctx->restart_header[substr]; ctx->cur_decoding_params = &ctx->major_decoding_params[1][substr]; @@ -2209,8 +2209,7 @@ static void process_major_frame(MLPEncodeContext *ctx) generate_2_noise_channels(ctx); rematrix_channels (ctx); - for (channel = rh->min_channel; channel <= rh->max_channel; channel++) - apply_filter(ctx, channel); + apply_filters(ctx); } } From patchwork Fri Jan 24 10:33:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jai Luthra X-Patchwork-Id: 17507 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 1F00E44ACAD for ; Fri, 24 Jan 2020 13:41:38 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F361768AFD0; Fri, 24 Jan 2020 13:41:37 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-vk1-f196.google.com (mail-vk1-f196.google.com [209.85.221.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8E50368AFBC for ; Fri, 24 Jan 2020 13:41:31 +0200 (EET) Received: by mail-vk1-f196.google.com with SMTP id i4so525424vkc.3 for ; Fri, 24 Jan 2020 03:41:31 -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=QtIvMlR+nSNaaH+oLsKa341yhDwPnx15M1hd0xcNM2A=; b=GjN60D8c4Sxu+71tQZ+7+yHCTvIBgl182824vdei3y/2nasjkbZdHg3MhdzmDwjZOF ore+ay2lq7Bwg3p247HTQ5NLjMO9WPxgddH1aHUkCJcRPINfS1ZgQOsPkMXRgBkFSm+d 97oN5BdazlBqO0E2lNr2WdsUWPla6erQOV5l/8V+dfN5WcWgkFqchgrvcTH4d3R9GINy lVjtr0ieE29fb2/Et9ZwgitNMDBFdyIAIGQaiouBjolWr5mNw7+LKhsQiQEBDOiXSCba zVhuOhTWn7krqCj5RgNIw553r4wgEWdycheWvzyKGUZWr88w1YsC22c3XIJmkB1Uo/Xl a2Bw== 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=QtIvMlR+nSNaaH+oLsKa341yhDwPnx15M1hd0xcNM2A=; b=ZWH7t6sf6u/X6lqQewGKNtK4PFwbR3+sCkOGRWhxBAgXcHT1f/vXhCSRaCb7jTKF8h IeBUKpefAYnsmy1nY4wBTO3B2P9w3y3ltWpe6zRGzhKHqP7K63kRHlhcmV1NGNf1lIc+ X4jEP6oLgbJwKkBVSYCT6Mv1rESzISwaAAfDWgm+aIsC9sB2qqqoPgNcCbTbeL3yryfP dinXP6v30ffcZevOj8Kf0wBfGEn1Q603piUZJGQzHBv5sMWNvw7T+Osss9abX6x3ZT1E 3E0diL6kDs+hO1NMNeCjQ6dJZazA935iBaQN/BO9gKdXUqW5kttBpu6B4cmwAHlgnxhp 2IRw== X-Gm-Message-State: APjAAAUwz/7aVQLQKGHuNx4QBOo0GEpPr/YVwkc1M8AiV8yNLgpHgwBk pzRj/7XC1ehIKg+XyX9GLHhdZQm49eQ= X-Google-Smtp-Source: APXvYqzP1oZ5YChLkrp6YekWH4rbglSiksMC3WIUkIxdIGWblSd+c4O6zIoNeGmOEHgocbqDJvharQ== X-Received: by 2002:a17:902:b40b:: with SMTP id x11mr2993117plr.268.1579862031914; Fri, 24 Jan 2020 02:33:51 -0800 (PST) Received: from localhost.localdomain ([49.207.55.142]) by smtp.googlemail.com with ESMTPSA id j125sm5471274pfg.160.2020.01.24.02.33.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2020 02:33:51 -0800 (PST) From: Jai Luthra To: ffmpeg-devel@ffmpeg.org Date: Fri, 24 Jan 2020 16:03:34 +0530 Message-Id: <20200124103334.110855-6-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 5/5] mlpenc: clean up 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" Signed-off-by: Jai Luthra --- libavcodec/mlpenc.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/libavcodec/mlpenc.c b/libavcodec/mlpenc.c index 0e7a9b7640..40872c42fa 100644 --- a/libavcodec/mlpenc.c +++ b/libavcodec/mlpenc.c @@ -94,8 +94,8 @@ typedef struct BestOffset { int16_t max; } BestOffset; -#define HUFF_OFFSET_MIN -16384 -#define HUFF_OFFSET_MAX 16383 +#define HUFF_OFFSET_MIN (-16384) +#define HUFF_OFFSET_MAX ( 16383) /** Number of possible codebooks (counting "no codebooks") */ #define NUM_CODEBOOKS 4 @@ -808,7 +808,7 @@ static void write_major_sync(MLPEncodeContext *ctx, uint8_t *buf, int buf_size) static void write_restart_header(MLPEncodeContext *ctx, PutBitContext *pb) { RestartHeader *rh = ctx->cur_restart_header; - int32_t lossless_check = xor_32_to_8(rh->lossless_check_data); + uint8_t lossless_check = xor_32_to_8(rh->lossless_check_data); unsigned int start_count = put_bits_count(pb); PutBitContext tmpb; uint8_t checksum; @@ -1017,12 +1017,10 @@ static void write_block_data(MLPEncodeContext *ctx, PutBitContext *pb) codebook_index [ch] = cp->codebook - 1; sign_huff_offset[ch] = cp->huff_offset; - sign_shift = lsb_bits[ch] - 1; + sign_shift = lsb_bits[ch] + (cp->codebook ? 2 - cp->codebook : -1); - if (cp->codebook > 0) { + if (cp->codebook > 0) sign_huff_offset[ch] -= 7 << lsb_bits[ch]; - sign_shift += 3 - cp->codebook; - } /* Unsign if needed. */ if (sign_shift >= 0) @@ -1032,7 +1030,6 @@ static void write_block_data(MLPEncodeContext *ctx, PutBitContext *pb) for (i = 0; i < dp->blocksize; i++) { for (ch = rh->min_channel; ch <= rh->max_channel; ch++) { int32_t sample = *sample_buffer++ >> dp->quant_step_size[ch]; - sample -= sign_huff_offset[ch]; if (codebook_index[ch] >= 0) { @@ -1252,7 +1249,7 @@ static void input_data_internal(MLPEncodeContext *ctx, const uint8_t *samples, uint32_t abs_sample; int32_t sample; - sample = is24 ? *samples_32++ >> 8 : *samples_16++ << 8; + sample = is24 ? *samples_32++ >> 8 : *samples_16++ * 256U; /* TODO Find out if number_sbits can be used for negative values. */ abs_sample = FFABS(sample); @@ -1795,7 +1792,7 @@ static void determine_bits(MLPEncodeContext *ctx) #define SAMPLE_MAX(bitdepth) ((1 << (bitdepth - 1)) - 1) #define SAMPLE_MIN(bitdepth) (~SAMPLE_MAX(bitdepth)) -#define MSB_MASK(bits) (-1u << bits) +#define MSB_MASK(bits) (-(1u << (bits))) /** Applies the filter to the current samples, and saves the residual back * into the samples buffer. If the filter is too bad and overflows the @@ -1899,8 +1896,8 @@ static void generate_2_noise_channels(MLPEncodeContext *ctx) for (i = 0; i < ctx->number_of_samples; i++) { uint16_t seed_shr7 = seed >> 7; - *sample_buffer++ = ((int8_t)(seed >> 15)) << rh->noise_shift; - *sample_buffer++ = ((int8_t) seed_shr7) << rh->noise_shift; + *sample_buffer++ = ((int8_t)(seed >> 15)) * (1 << rh->noise_shift); + *sample_buffer++ = ((int8_t) seed_shr7) * (1 << rh->noise_shift); seed = (seed << 16) ^ seed_shr7 ^ (seed_shr7 << 5); @@ -2071,9 +2068,10 @@ static void set_best_codebook(MLPEncodeContext *ctx) best_codebook = *best_path++ - ZERO_PATH; cur_bo = &ctx->best_offset[index][channel][best_codebook]; - cp->huff_offset = cur_bo->offset; - cp->huff_lsbs = cur_bo->lsb_bits + dp->quant_step_size[channel]; - cp->codebook = best_codebook; + cp->huff_offset = cur_bo->offset; + cp->sign_huff_offset = -(1 << 23); + cp->huff_lsbs = cur_bo->lsb_bits + dp->quant_step_size[channel]; + cp->codebook = best_codebook; } } } @@ -2275,7 +2273,7 @@ static int mlp_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, if (restart_frame) { set_major_params(ctx); if (ctx->min_restart_interval != ctx->max_restart_interval) - process_major_frame(ctx); + process_major_frame(ctx); } if (ctx->min_restart_interval == ctx->max_restart_interval) From patchwork Sun Feb 2 19:02:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jai Luthra X-Patchwork-Id: 17662 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 DA9CD44B481 for ; Sun, 2 Feb 2020 21:03:13 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C695A688173; Sun, 2 Feb 2020 21:03:13 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from new4-smtp.messagingengine.com (new4-smtp.messagingengine.com [66.111.4.230]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 67EB5687FE0 for ; Sun, 2 Feb 2020 21:03:06 +0200 (EET) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailnew.nyi.internal (Postfix) with ESMTP id E62876837 for ; Sun, 2 Feb 2020 14:03:04 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Sun, 02 Feb 2020 14:03:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jailuthra.in; h= from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=4IlvduUv/7az4 JyUWj7w7giA2Osw4EKy6Ctt/AGdujU=; b=GYxybbJeUUDsywewBKBF7cMzNra9F tZbKnglyFw9GMIy9ZdXud5x2PB4kLUFuQ3KU6jlwlwD0XDgChCPfmiKQi+uNy87h 3XW9eFX707TzXqTr5s5DRugAgGw6Caua8cFFSI7Q64RXzDmFbqEhg3XbQijLQPLN kLQeeaEQrPf7ex1MSTE4l7TKtjhsYjaXAFPghc6xtde33/yOrsq0n1zHnm1gxaji mqT5MpweSdCup0x7qL1u+myw1T2V4X6WYfXIp1/A6kTMLoBm3+2WKm8Ifiw75YyS +IA/XA0X8vTZoqgdn4wGi5k7jvZhvjrxWQQ2xYUHEE9i99RYi7zpwvxgQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=4IlvduUv/7az4JyUWj7w7giA2Osw4EKy6Ctt/AGdujU=; b=nWVkkmgz NHC3bEoJV+4BzaQIHDEXrYGzFApl7ijsRSLamN8wRTvoCwEqSmwDIfRgckhbqMjm afAhuQAwAmCRio8byv3PNeSAHU1vbL22Z6CJLKeMmZJZoTWVaciigZoP26mFD0+t 0gBWDFN+cfn0jmNntA8DTDGfFOBDuQy+RZjttggqlivjMtLleeto3lT1PkvESm4H gNez3tdUGMwRvTzFGlOz4evqFX+Jo+rgJwlwAiG7xGki8rxZWGZemClneVi3bsfP hG3gnTQXH3sytmt61DMZ6TSsSclzqSpdzVY7jNnhhJyYoY0sr/Ykjr47F+VfUJBy HHChT6GcXv4gBA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrgeehgdduudelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomheplfgrihcunfhuthhhrhgruceomhgvsehjrghilhhuthhhrhgr rdhinheqnecukfhppeegledrvddtjedrheehrddugedvnecuvehluhhsthgvrhfuihiivg eptdenucfrrghrrghmpehmrghilhhfrhhomhepmhgvsehjrghilhhuthhhrhgrrdhinh X-ME-Proxy: Received: from localhost.localdomain (unknown [49.207.55.142]) by mail.messagingengine.com (Postfix) with ESMTPA id 9BF5D306015E for ; Sun, 2 Feb 2020 14:03:03 -0500 (EST) From: Jai Luthra To: ffmpeg-devel@ffmpeg.org Date: Mon, 3 Feb 2020 00:32:59 +0530 Message-Id: <20200202190300.156267-1-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 6/7] mlpenc: fix -fsanitize=integer errors 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" Signed-off-by: Jai Luthra --- libavcodec/mlpenc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) Thanks to Paul for the original pastebin patch diff --git a/libavcodec/mlpenc.c b/libavcodec/mlpenc.c index 347a43248c..af04648097 100644 --- a/libavcodec/mlpenc.c +++ b/libavcodec/mlpenc.c @@ -87,11 +87,11 @@ typedef struct { } DecodingParams; typedef struct BestOffset { - int16_t offset; + int32_t offset; int bitcount; int lsb_bits; - int16_t min; - int16_t max; + int32_t min; + int32_t max; } BestOffset; #define HUFF_OFFSET_MIN (-16384) @@ -1249,7 +1249,7 @@ static void input_data_internal(MLPEncodeContext *ctx, const uint8_t *samples, uint32_t abs_sample; int32_t sample; - sample = is24 ? *samples_32++ >> 8 : *samples_16++ * 256U; + sample = is24 ? *samples_32++ >> 8 : *samples_16++ * 256; /* TODO Find out if number_sbits can be used for negative values. */ abs_sample = FFABS(sample); @@ -1792,7 +1792,7 @@ static void determine_bits(MLPEncodeContext *ctx) #define SAMPLE_MAX(bitdepth) ((1 << (bitdepth - 1)) - 1) #define SAMPLE_MIN(bitdepth) (~SAMPLE_MAX(bitdepth)) -#define MSB_MASK(bits) (-(1u << (bits))) +#define MSB_MASK(bits) (-(int)(1u << (bits))) /** Applies the filter to the current samples, and saves the residual back * into the samples buffer. If the filter is too bad and overflows the From patchwork Sun Feb 2 19:03:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jai Luthra X-Patchwork-Id: 17663 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 8F11144B481 for ; Sun, 2 Feb 2020 21:03:14 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 80A3D688191; Sun, 2 Feb 2020 21:03:14 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from new4-smtp.messagingengine.com (new4-smtp.messagingengine.com [66.111.4.230]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1A40B687FE0 for ; Sun, 2 Feb 2020 21:03:07 +0200 (EET) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailnew.nyi.internal (Postfix) with ESMTP id 384D268AF for ; Sun, 2 Feb 2020 14:03:06 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Sun, 02 Feb 2020 14:03:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jailuthra.in; h= from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=hufq26b0K5k5y Qz0LF7mQl9YmhZcLeLpVJT8ptxbiU0=; b=r0dRnvlCYkoJ4JMuWn8276jV/hwAr KgRI2uhfpXlbEmfRJBwcBCDBvTIjaV0TMv0L121gVa4wmF2yKHpf38/dYWBgwKDu TWzWg1qLAXDuksRpcFctsOeVfpi/rof1pV/DWq6L3svfKql8s6Y0OgNUBjFWVuQV i6d/cwvrOMzlgdkj+aJRXF4n72qMBR0a7jNIBVu0q+YQ4/apH+a4swB+YZUv1WNG dBsLcHrjb6s1K1eZ+JYBnHkr7jZ1/WLq7z4mZ3M57QJi88AuGatSmqvLl4hyyVQW s+O4C3TMjXSI5IB8VQc5xitY/Gz6MECJi1NUZ41RocRoXH42OLsPVhXLA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=hufq26b0K5k5yQz0LF7mQl9YmhZcLeLpVJT8ptxbiU0=; b=At/pVhbO EnKD5VLsGojQRNSbWpG5wY33czxCDDXNgGwI6wwrofGE5VZ5ZmOxrdkc0rkwtd78 f4XTLX/KLiyZa/xK3ZW+7mL9d/h6EaanUbJ281ZxnQe5ArtuvfsRDHoHQMdDtmIt b7y4aWEv8GI/REjSvMFoRbmE2vb0fXEDCmKDzaDeIVGTUhgUCM0GeJNgxcgo0nuU e3cOn78ZqhYG/ofN5jzAohakqP8PsnQHZS0OUkPmHY3aVbXRtvhWuc8WNPApGJ1P WD907MR+8fOA2oor/OOl0pJ9YLsrZazSbdo000BjX0HPCTM1NKU2/1aI5h2rF7Sa /gxrrqaALWcmjg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrgeehgdduudelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomheplfgrihcunfhuthhhrhgruceomhgvsehjrghilhhuthhhrhgr rdhinheqnecuffhomhgrihhnpehlhihnnhgvrdgvvgenucfkphepgeelrddvtdejrdehhe drudegvdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhm pehmvgesjhgrihhluhhthhhrrgdrihhn X-ME-Proxy: Received: from localhost.localdomain (unknown [49.207.55.142]) by mail.messagingengine.com (Postfix) with ESMTPA id A721B30602AD for ; Sun, 2 Feb 2020 14:03:04 -0500 (EST) From: Jai Luthra To: ffmpeg-devel@ffmpeg.org Date: Mon, 3 Feb 2020 00:33:00 +0530 Message-Id: <20200202190300.156267-2-me@jailuthra.in> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200202190300.156267-1-me@jailuthra.in> References: <20200124103334.110855-1-me@jailuthra.in> <20200202190300.156267-1-me@jailuthra.in> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 7/7] mlp: check huff_lsbs only when codebook is used 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" When no codebook is used, huff_lsbs can be more than 24 and still decode to original values once filters are applied. Signed-off-by: Jai Luthra --- libavcodec/mlpdec.c | 2 +- libavcodec/mlpenc.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) Fixes lossless check failures caused with https://lynne.ee/files/sample.flac diff --git a/libavcodec/mlpdec.c b/libavcodec/mlpdec.c index 39c40914cd..22a6efd63d 100644 --- a/libavcodec/mlpdec.c +++ b/libavcodec/mlpdec.c @@ -829,7 +829,7 @@ static int read_channel_params(MLPDecodeContext *m, unsigned int substr, cp->codebook = get_bits(gbp, 2); cp->huff_lsbs = get_bits(gbp, 5); - if (cp->huff_lsbs > 24) { + if (cp->codebook > 0 && cp->huff_lsbs > 24) { av_log(m->avctx, AV_LOG_ERROR, "Invalid huff_lsbs.\n"); cp->huff_lsbs = 0; return AVERROR_INVALIDDATA; diff --git a/libavcodec/mlpenc.c b/libavcodec/mlpenc.c index af04648097..4e60ffd217 100644 --- a/libavcodec/mlpenc.c +++ b/libavcodec/mlpenc.c @@ -987,6 +987,9 @@ static void write_decoding_params(MLPEncodeContext *ctx, PutBitContext *pb, put_bits(pb, 1, 0); } } + if (cp->codebook > 0 && cp->huff_lsbs > 24) { + av_log(ctx->avctx, AV_LOG_ERROR, "Invalid Huff LSBs\n"); + } put_bits(pb, 2, cp->codebook ); put_bits(pb, 5, cp->huff_lsbs);