From patchwork Thu Oct 22 14:56:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23150 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 70F5144A593 for ; Thu, 22 Oct 2020 17:56:41 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4643968A494; Thu, 22 Oct 2020 17:56:41 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0E472689DBD for ; Thu, 22 Oct 2020 17:56:35 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id g12so2811510wrp.10 for ; Thu, 22 Oct 2020 07:56:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=qPsIyZJN15Oer8olIc2hnVqOPNMm0FAGEDicK7rt4I8=; b=X5vdb5TpWz0E1lqOtc3ANpKeBflat0b6zaooJIiRBPonOnqad/ldnGDHKOIqaCxOvb /lkQA4MnjWCvc6con8ZJuwxlrzPihsyZSLepd0ZPvyppu1mTA7ThYg8HVTpvtkCv8ECe A6hH/hFeA+SJimFTggvGHgW6++F9sO1SkQNT0uAo1gir14931urtDog9BoEFpyHmGLXR eFmH1X5aNPNDtXkeCtPFffdLMVRfMJpCdndjpxbCrZch4TaqldmXRCpLjheHzdVs+iqN jid6DOkWedosvLQiUrjrwmsS0nTdLnkbZUXErnhPfv1ao+rEFjhzGrRk1EJ7HW3K4632 JVww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=qPsIyZJN15Oer8olIc2hnVqOPNMm0FAGEDicK7rt4I8=; b=IoV0LRAbyDaGmfPOd/RqAY2wup8XMEVLnrIKvfq1yzOwGx6zdNdB5N1DHP8Amm/XTS qDYuDeyZ6Jy/qrxXx0IoBOFubCVrOAMJREf5QQg/KylcSBP2ltVt7BH/CTE8CLwESAaD EGTtQi4NJSLXuvjnknaGQKNoCQOwEo1/sUFq9py5lfOGegTcXVeoEnScc9d3ee7KgXw5 7d+PBGnagdD7rqnOFOS0EOAl9F7s8eQFsLOOk/9McU8A8RLk/GGfU8SPIAxPBjnR/xdN /2+sZGIDy+6Kt/exW5aSgIbh2oJ6YsEZX39G2rfK3U9rayZ+UOl1w35PjPhtarDzHreF E25Q== X-Gm-Message-State: AOAM530A6XLNzj7PL3iVMPwUXFonITKqn8kF+6cMx12HOcVcI9AC1WpG DaB8ls67DLdVY8a6sCljuBHma+ziqUI= X-Google-Smtp-Source: ABdhPJy4P51ULY+H2/N4PBAs4pJGw8V7CY2Tbk1tETzuDhikJkeM3cTRUbs0lCnFGCAGvxen3HHTpg== X-Received: by 2002:adf:fb8b:: with SMTP id a11mr3097351wrr.407.1603378594138; Thu, 22 Oct 2020 07:56:34 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id a3sm4711652wrh.94.2020.10.22.07.56.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2020 07:56:33 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 22 Oct 2020 16:56:22 +0200 Message-Id: <20201022145624.657457-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] avcodec/webp: Use uint8_t for code lengths 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" They are always in the range 0..15, so using an int is not necessary. Furthermore, using an int would not work if sizeof(int) == 4 as ff_init_vlc_sparse() can only handle uint8_t, uint16_t and uint32_t lengths. Signed-off-by: Andreas Rheinhardt --- libavcodec/webp.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavcodec/webp.c b/libavcodec/webp.c index 6140c7ea4a..6b53a7f17c 100644 --- a/libavcodec/webp.c +++ b/libavcodec/webp.c @@ -243,7 +243,7 @@ static int huff_reader_get_symbol(HuffReader *r, GetBitContext *gb) return get_vlc2(gb, r->vlc.table, 8, 2); } -static int huff_reader_build_canonical(HuffReader *r, int *code_lengths, +static int huff_reader_build_canonical(HuffReader *r, const uint8_t *code_lengths, int alphabet_size) { int len = 0, sym, code = 0, ret; @@ -324,8 +324,8 @@ static int read_huffman_code_normal(WebPContext *s, HuffReader *hc, int alphabet_size) { HuffReader code_len_hc = { { 0 }, 0, 0, { 0 } }; - int *code_lengths = NULL; - int code_length_code_lengths[NUM_CODE_LENGTH_CODES] = { 0 }; + uint8_t *code_lengths = NULL; + uint8_t code_length_code_lengths[NUM_CODE_LENGTH_CODES] = { 0 }; int i, symbol, max_symbol, prev_code_len, ret; int num_codes = 4 + get_bits(&s->gb, 4); @@ -340,7 +340,7 @@ static int read_huffman_code_normal(WebPContext *s, HuffReader *hc, if (ret < 0) goto finish; - code_lengths = av_mallocz_array(alphabet_size, sizeof(*code_lengths)); + code_lengths = av_mallocz(alphabet_size); if (!code_lengths) { ret = AVERROR(ENOMEM); goto finish; From patchwork Thu Oct 22 14:56:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23151 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 130FB44A65A for ; Thu, 22 Oct 2020 17:57:45 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E3DC468A8F8; Thu, 22 Oct 2020 17:57:44 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0AD4D689C7E for ; Thu, 22 Oct 2020 17:57:39 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id x7so2836550wrl.3 for ; Thu, 22 Oct 2020 07:57:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SgD6WD85VPuGWE3JRytIPoEpVxBJxCSP0lPI7z2LhZ8=; b=WOwaKdT81q0MoT76RPUlOTeRe+t+4qQQPiLwLpmJkYiLj9SB5m5mEW9zRdaPfoe3fU jEtUA7e9ThYCzZBHW10poJWB2dBFff1Y2/TQNuLJL/rIMPt/2BQtF3+GIlXBuEmf63K2 qqhdblZs21UKHwTYKHJ82NfNbiqYn0YO3ZwMqJ0meeuR2B6YcqaxHnQzOHES+qswKtw5 oAmKwg/8v3tM0thLNK3wpNd2b16Q608BNe037E4/9Znr7p5L/DFDrXtMECxF34GhZL// eW5kZ+m8aE1r6U1o+ZaXGe580Wl7wCzJyxCSS6GA39YY3h3kTglHFMMORztkgSuwMN9y tF/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SgD6WD85VPuGWE3JRytIPoEpVxBJxCSP0lPI7z2LhZ8=; b=E4ZD6LG0xZqnLKPJHmsIDI/DOd0SPOVeLeI/3PSGBJDeoz7i0vd5ONRpD9EoBLAexa u5BFAcgveBn8mjvjwt00pzrPLf+bJiyEwhFV2qfobllQS1IlcLD/IM4ycTWO2KmKH3+L qQzOC1HllqGMctqsVRDRJf+B69J73CwcMAhyteKy6M5gk9M8Im5uCPRKgCtKNhYWmADa r3/usEF1qNbkuIgehDax3rp6Ozh4AWWaqAy378F+YrVnc5zSBvYwZ9xviMYlBXcpeYmB 4UFxoiEmtgJI/TeuAZeIFfpUiXHqLxgwbS2V5ijpRNWJjaIbBGNYT7L5FaogzFWBKFPm rZPQ== X-Gm-Message-State: AOAM531X+It7699MlFJhZJZO81/YvyzC8d/OiSArNQt9On+avqAaEVWx KdWGsoLawT5ruskcHS3nSqP2GaYUKX4= X-Google-Smtp-Source: ABdhPJzGXo4tNs86xgvfCND8WifEHP7FotjA+BPYvBksPuC25r8UN32fATClaVUIpmHC9FRtuRbWXw== X-Received: by 2002:adf:f44b:: with SMTP id f11mr3116339wrp.411.1603378658358; Thu, 22 Oct 2020 07:57:38 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id a3sm4711652wrh.94.2020.10.22.07.57.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2020 07:57:37 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 22 Oct 2020 16:56:23 +0200 Message-Id: <20201022145624.657457-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201022145624.657457-1-andreas.rheinhardt@gmail.com> References: <20201022145624.657457-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] avcodec/webp: Return directly when creating Huff table fails 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Neither the auxiliary VLC table nor the code_lengths array need to be freed if creating the auxiliary VLC table fails. Signed-off-by: Andreas Rheinhardt --- libavcodec/webp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/webp.c b/libavcodec/webp.c index 6b53a7f17c..549d125dcc 100644 --- a/libavcodec/webp.c +++ b/libavcodec/webp.c @@ -324,7 +324,7 @@ static int read_huffman_code_normal(WebPContext *s, HuffReader *hc, int alphabet_size) { HuffReader code_len_hc = { { 0 }, 0, 0, { 0 } }; - uint8_t *code_lengths = NULL; + uint8_t *code_lengths; uint8_t code_length_code_lengths[NUM_CODE_LENGTH_CODES] = { 0 }; int i, symbol, max_symbol, prev_code_len, ret; int num_codes = 4 + get_bits(&s->gb, 4); @@ -338,7 +338,7 @@ static int read_huffman_code_normal(WebPContext *s, HuffReader *hc, ret = huff_reader_build_canonical(&code_len_hc, code_length_code_lengths, NUM_CODE_LENGTH_CODES); if (ret < 0) - goto finish; + return ret; code_lengths = av_mallocz(alphabet_size); if (!code_lengths) { From patchwork Thu Oct 22 14:56:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23152 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 31D2544A65A for ; Thu, 22 Oct 2020 17:57:47 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1E29068AE9A; Thu, 22 Oct 2020 17:57:47 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 144C668AA85 for ; Thu, 22 Oct 2020 17:57:40 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id a72so2431806wme.5 for ; Thu, 22 Oct 2020 07:57:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=V93Hkx3Bpneck+NbrjDohR4j8U+kKzavlu1HaPO2yHE=; b=iEVETG0m5Zw5k3S39mXOMNGFEY49IKD8T7wFcs25cvWFpYFfO2YeOyXXU1sQfpUqgO xGdaz2owl1U4AnB7JjHJY3IObJJF22CAS2c93v9kiEL3S9E/10PIHS4S3U0UfVRt4dWR fgEmaZkp/rrqlvpR+diouxOWVM0fYpZ3qyg8D1MU+tCgU//25OfxikJ2JFIVY1bCgTy8 bOJXajBt08I/K8IyV510a9FbRx5UTVs2GaZpK3sSxqcHtB4REJBCNncV83D9q/GcAM/D JHQ7MBdoaVBr5x9iY20j7L+oDnOgZTmucSkb3KumTIwjK6975mJoa78HVhAfn7fkB4gQ vN9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=V93Hkx3Bpneck+NbrjDohR4j8U+kKzavlu1HaPO2yHE=; b=t+8WR/y7WgTvDHhnTq0OYTEtFgl0PNjWhUK5EJUl3j78qetcGdrP9vZzqEERCWN5dK ofNZRstG6vnP8wH1GIl4F6k6P1zrE621RKZdM2mndNMa7z12gh9km29sw3LBLcSCX1vp 7wxBJQk3ejD0Lti4QLJhhoByiJumDlVcJXSdl6VCOexmq9gUMF+rJy5jDfY9a+2JZVLi BBYHnHeYgCKsVjOeYz9dgVLaoTQ3ONrBAHnglU+f7/z+IAhRScGqSl1pMR69t9a5+byX j/dd27CoOmd7jt1uLw4OaeAWKewPlig1f6IgRbSM4j/9RjphnqVkTPy2i4e3HY5rG2jN VR+w== X-Gm-Message-State: AOAM530DEV+qb/MH3wx2K9/A7flCLTaVtV8MYE5P965UK5l/of1ijjb3 4IYDEGoNnjx+I/IwZSvH+yQB2bWVt7A= X-Google-Smtp-Source: ABdhPJwyI9B5quFMOOVZv5a33/wXW1XTb5uEuqsl+XHUhwqlwCbZqPr1CP1gz0iOgiS1n3kA6O3kRw== X-Received: by 2002:a1c:2402:: with SMTP id k2mr2867236wmk.158.1603378659306; Thu, 22 Oct 2020 07:57:39 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id a3sm4711652wrh.94.2020.10.22.07.57.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2020 07:57:38 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 22 Oct 2020 16:56:24 +0200 Message-Id: <20201022145624.657457-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201022145624.657457-1-andreas.rheinhardt@gmail.com> References: <20201022145624.657457-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] avcodec/webp: Replace never-true check by assert 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Andreas Rheinhardt --- libavcodec/webp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libavcodec/webp.c b/libavcodec/webp.c index 549d125dcc..6de6a5c036 100644 --- a/libavcodec/webp.c +++ b/libavcodec/webp.c @@ -329,8 +329,7 @@ static int read_huffman_code_normal(WebPContext *s, HuffReader *hc, int i, symbol, max_symbol, prev_code_len, ret; int num_codes = 4 + get_bits(&s->gb, 4); - if (num_codes > NUM_CODE_LENGTH_CODES) - return AVERROR_INVALIDDATA; + av_assert1(num_codes <= NUM_CODE_LENGTH_CODES); for (i = 0; i < num_codes; i++) code_length_code_lengths[code_length_code_order[i]] = get_bits(&s->gb, 3);