From patchwork Mon Oct 26 10:11:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23226 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 0BEFE44A374 for ; Mon, 26 Oct 2020 12:12:15 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CE2A068AA68; Mon, 26 Oct 2020 12:12:14 +0200 (EET) 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 CD8FA688035 for ; Mon, 26 Oct 2020 12:12:07 +0200 (EET) Received: by mail-wm1-f65.google.com with SMTP id e2so11841267wme.1 for ; Mon, 26 Oct 2020 03:12:07 -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:reply-to:mime-version :content-transfer-encoding; bh=Rk/++rSVJDnsowPvKEtKYM3U0iDhf0mSpj6MgXKuIDQ=; b=X58G3iMMqIo8IZ/BVvEatAGPiDXDFLEWlQxoyEiNWjVHtHl3TgGBwTpLOAATyTNi+l kJTbA8MDKtIvVCG6jxxS20xmAztAPlR0AN5vuPtJ5KG70Y3J8BtYJu95YF0rs9P7FNwT 5yC0p11bxwcm9ojlTwr1Sj+SCEXT2RGducP4jb1nCc+O8ZrD6hwX/Jre6uLtQpgeLpaC u0IsOI4R/CW4UnXFJQNzjt+9NaRy1p7gyhsXEHnOrquYpnS5Z8xktLhVuhfJ2/9AzpPX Qv/jRvuBd+7JyhcUL/ZNOtlINQfCOu3nAY29kxZa4Ddufsm1d7MTDzG81UuL4qsR3qPv FT0w== 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:reply-to :mime-version:content-transfer-encoding; bh=Rk/++rSVJDnsowPvKEtKYM3U0iDhf0mSpj6MgXKuIDQ=; b=uoCktRvQjPsM9rvAVdqrM0uTxIWtN9QI0eq5pvpW6vyzvRW5F0nqTdJ09Mx3Rgwrsg /ynT44pdaoWGBxIUL/C8tV+K2MURqY7z6xHSkMfR51ShYx544iJBEtaZQTLmeNTT5zwa 8fUbQ9vInIxkG2q3ZYxP9GtTfAtPsq+P4TxCYwcPjPIqa877kqPdyzH8K+u30SROeBYP mXCLuKovd+dWKiP4ZNkutZeACIZWcoKMbbuzU144yjru1jZ5HioOyIYgOkefQE39CySl bsUJxWChEOnlR+juWklHbD8UZbPLXyi4LgEMqXig83KJx2hyZNaz/OllyKNA8tW2m2z9 kSbg== X-Gm-Message-State: AOAM533cjvA65uwN/a6GFJDpkMW6lABcxl2Y1w/IjZHLUjuIW4CjxEZE lcUDT7Mqz8n/lXgW+UQ/jbZ0Ebmg4as= X-Google-Smtp-Source: ABdhPJw/fi42ZVvpq/plQfAbymi+0+T2myLYr1nUTowZ42PJULF9N07Uf/SEVWnZKVRh0nm6p6LgAA== X-Received: by 2002:a7b:c935:: with SMTP id h21mr14479808wml.99.1603707126825; Mon, 26 Oct 2020 03:12:06 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id n83sm21186337wma.39.2020.10.26.03.12.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2020 03:12:06 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 26 Oct 2020 11:11:48 +0100 Message-Id: <20201026101150.425151-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] avcodec/cllc: Don't unnecessarily free VLC 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" The Canopus Lossless decoder uses several VLCs and if initializing the ith VLC fails, all the VLCs 0..i have been freed; the ith VLC's table is initialized to NULL for this purpose. Yet it is totally unnecessary to free the ith VLC table at all: ff_init_vlc_sparse() cleans up after itself on error and if an error happens before ff_init_vlc_sparse(), the ith VLC hasn't been touched yet and doesn't need freeing. Signed-off-by: Andreas Rheinhardt --- libavcodec/cllc.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/libavcodec/cllc.c b/libavcodec/cllc.c index 1f2c98ef73..8b1bc75faa 100644 --- a/libavcodec/cllc.c +++ b/libavcodec/cllc.c @@ -57,8 +57,6 @@ static int read_code_table(CLLCContext *ctx, GetBitContext *gb, VLC *vlc) num_lens = get_bits(gb, 5); if (num_lens > VLC_BITS * VLC_DEPTH) { - vlc->table = NULL; - av_log(ctx->avctx, AV_LOG_ERROR, "To long VLCs %d\n", num_lens); return AVERROR_INVALIDDATA; } @@ -68,8 +66,6 @@ static int read_code_table(CLLCContext *ctx, GetBitContext *gb, VLC *vlc) num_codes_sum += num_codes; if (num_codes_sum > 256) { - vlc->table = NULL; - av_log(ctx->avctx, AV_LOG_ERROR, "Too many VLCs (%d) to be read.\n", num_codes_sum); return AVERROR_INVALIDDATA; @@ -83,7 +79,6 @@ static int read_code_table(CLLCContext *ctx, GetBitContext *gb, VLC *vlc) count++; } if (prefix > (65535 - 256)/2) { - vlc->table = NULL; return AVERROR_INVALIDDATA; } @@ -247,7 +242,7 @@ static int decode_argb_frame(CLLCContext *ctx, GetBitContext *gb, AVFrame *pic) for (i = 0; i < 4; i++) { ret = read_code_table(ctx, gb, &vlc[i]); if (ret < 0) { - for (j = 0; j <= i; j++) + for (j = 0; j < i; j++) ff_free_vlc(&vlc[j]); av_log(ctx->avctx, AV_LOG_ERROR, @@ -290,7 +285,7 @@ static int decode_rgb24_frame(CLLCContext *ctx, GetBitContext *gb, AVFrame *pic) for (i = 0; i < 3; i++) { ret = read_code_table(ctx, gb, &vlc[i]); if (ret < 0) { - for (j = 0; j <= i; j++) + for (j = 0; j < i; j++) ff_free_vlc(&vlc[j]); av_log(ctx->avctx, AV_LOG_ERROR, @@ -343,7 +338,7 @@ static int decode_yuv_frame(CLLCContext *ctx, GetBitContext *gb, AVFrame *pic) for (i = 0; i < 2; i++) { ret = read_code_table(ctx, gb, &vlc[i]); if (ret < 0) { - for (j = 0; j <= i; j++) + for (j = 0; j < i; j++) ff_free_vlc(&vlc[j]); av_log(ctx->avctx, AV_LOG_ERROR, From patchwork Mon Oct 26 10:11:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23227 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 3A20D44A374 for ; Mon, 26 Oct 2020 12:12:30 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 17EA668AC37; Mon, 26 Oct 2020 12:12:30 +0200 (EET) 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 4D88268A8B9 for ; Mon, 26 Oct 2020 12:12:24 +0200 (EET) Received: by mail-wr1-f66.google.com with SMTP id e17so11698441wru.12 for ; Mon, 26 Oct 2020 03:12:24 -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:reply-to :mime-version:content-transfer-encoding; bh=PGsFaqAJfYMoqf59w2kaB0ide6YwBwE7Ulo4czyi1lE=; b=e8LpVaXX42RbF9cIUW3yf7bj/iqa+0AfUfXMqumVPz2TLv2+LXrTxvbdr61VRbU09q CUWWRyVN5EroUexxJn4oJ7NkDCeQ9c7Bgt0deEiBoTqW4oG6u1VRRzImBSjr+ZZ4VLex 5m9A7a7WjRh235VxEyTEBu4JTvgh1KqhudF5FbLifa/QDwspc0NxOPxEcXAtDZwDtUYy F9LhDQ3eyCOEe5mJZDj8Xs/S/Hjl1PrVi36OGUJaOmqAmamMJ54JBui01ILD9jDoL+cP 8kq9o2bidygTpMdD2Se2/Cd2frPuL42WLvNQAdlboBwmrS0d/MgFYrzA4VW38IapdD+2 /esQ== 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:reply-to:mime-version:content-transfer-encoding; bh=PGsFaqAJfYMoqf59w2kaB0ide6YwBwE7Ulo4czyi1lE=; b=dm8Ac9yTPZgVvwseuVWA/thqbMbHrxrK7Kwzqkkj4+7rF7XKflQS1TVDQBAlw6P/7U e+5DhR1vkYOz1zhWlR66ddMY9NtcCmKmDNUm061mijtBmHFS/n0cO4l8d8/n9wx44dq+ kTF/lJEUAAUBbLVVN0HTaUtTvjT/bjaxI3ADE+3GRTPxTgVJ1O/4F5pMoFJQb/G14dpW 1pyaRX50t3uHea7/VVB6KF6oNHY6qeEPDRXL9d6lpMSZZzp4owZEDoUzw0SsVJdU5M06 GhIfg9MNPQK6mCzY1Utuu32qpXW9vq+MteQJvqEkIof2uXo5ArvU+XOvTr75cpjjQ0hb sSYw== X-Gm-Message-State: AOAM532C9ZvW68KRmxhcPGAU5cSy82TS3g5jYbg5DKeCHhyBrQ1IeBDS 76RK9xczpw/nJ9IUgM5a9/zSzNrpMjA= X-Google-Smtp-Source: ABdhPJwYJaC1pX//fgQvP0rb1LiJdNO2x3Jy+9u2cJ2j5kviokxCgqGFdJmP4+9thhOfcIC/9XidyQ== X-Received: by 2002:adf:92a1:: with SMTP id 30mr17009002wrn.269.1603707143577; Mon, 26 Oct 2020 03:12:23 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id n83sm21186337wma.39.2020.10.26.03.12.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2020 03:12:23 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 26 Oct 2020 11:11:49 +0100 Message-Id: <20201026101150.425151-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201026101150.425151-1-andreas.rheinhardt@gmail.com> References: <20201026101150.425151-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] avcodec/vp3: Don't check for errors for complete VLC 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/vp3.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c index 51be4ebf05..c4ad43a299 100644 --- a/libavcodec/vp3.c +++ b/libavcodec/vp3.c @@ -682,11 +682,6 @@ static int vp4_get_mb_count(Vp3DecodeContext *s, GetBitContext *gb) static int vp4_get_block_pattern(Vp3DecodeContext *s, GetBitContext *gb, int *next_block_pattern_table) { int v = get_vlc2(gb, s->block_pattern_vlc[*next_block_pattern_table].table, 3, 2); - if (v == -1) { - av_log(s->avctx, AV_LOG_ERROR, "Invalid block pattern\n"); - *next_block_pattern_table = 0; - return 0; - } *next_block_pattern_table = vp4_block_pattern_table_selector[v]; return v + 1; } From patchwork Mon Oct 26 10:11:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23228 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 272EA44A374 for ; Mon, 26 Oct 2020 12:12:33 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1552D68AD4C; Mon, 26 Oct 2020 12:12:33 +0200 (EET) 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 3C39268ACE4 for ; Mon, 26 Oct 2020 12:12:25 +0200 (EET) Received: by mail-wr1-f66.google.com with SMTP id i1so11726442wro.1 for ; Mon, 26 Oct 2020 03:12:25 -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:reply-to :mime-version:content-transfer-encoding; bh=q5vw+kbHceI/NKueYa3AFcRiIw8ZMiBSkGSezMDCPpo=; b=RYFSPsCgLXZxjhkYTRB3H5FayQDPLa9jU568Rry6sbmOz4eNh7sBIGAci2i+sZ/5nI UFbKWYNig2UoM7kDSt5pIwGRnQhyn/2hG19Q3efMEoTVVOtK0p21iOjvNBDldBYiE4rT ITB4NXW5MjsGuTe14oQKpDevOAM13IdRCNsZ4Fkq3PABOkItOcDDiaUSAoZ7e2tkMT/V ZH+q3SC2Ky9cgD+TrMTm3bt/T9B2bD6u64T0DAIXRAnp/GkeGh4xHp39FoB//RGkzJoC +/Fp7QVncfmINnYYOQI4sthW++v5dA8BJzdRnKCOONMcphkBvEn9R89fuaZOWZhOfcy8 Fjig== 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:reply-to:mime-version:content-transfer-encoding; bh=q5vw+kbHceI/NKueYa3AFcRiIw8ZMiBSkGSezMDCPpo=; b=oZnCBPk7kTrIce3E4JRRkJcCkyLLGBwbEfMh4bUGKxGo42emOcrf7k8gmrQ8bmQAN8 ozRNEDS4bMqe5nVg7+AciLCNk1FNyrwfkn4I6lguBjigkRo/96Q6o0NDA1FhU3/dZV4J ij5CuUuov0/JXj6t5WIF15tWHeChiIsJFODg9kPBLDXNf7ueIkplwz216gCmKCHyBf4y iX+gpj5jbwTEuj4notcjvOb5Y1Bj99dpaKpq3gHu4FDu6LJSCUmyJFtxktKjZy8zC6H/ DEH/IXT/vqdG/IvO9CaxZ/l1P8vi+jOYOa1yivmGE8cr5jswYEIE9f7o5/6OerS76jnG DELA== X-Gm-Message-State: AOAM532+z60TL+L7NjwCOeqPegp3g0hbjCEnafrJfxzCYfgxssx2xahj KTn6Icfdp6eUvuwPSzj1gMBAK7fQ9j8= X-Google-Smtp-Source: ABdhPJwPetI+s/72m/dLwth9Rwe97/jwQTaM+Hlh1NPm+IYHgl7xzmRpx6I23cReD+A/g1ygUE664A== X-Received: by 2002:adf:e8d0:: with SMTP id k16mr16613928wrn.362.1603707144438; Mon, 26 Oct 2020 03:12:24 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id n83sm21186337wma.39.2020.10.26.03.12.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2020 03:12:23 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 26 Oct 2020 11:11:50 +0100 Message-Id: <20201026101150.425151-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201026101150.425151-1-andreas.rheinhardt@gmail.com> References: <20201026101150.425151-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] avcodec/bitstream: Consistently treat symbol as VLC_TYPE 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" If a static VLC table gets initialized a second time (or concurrently by two threads) and if said VLC table uses symbols that have the sign bit of VLC_TYPE (a typedef for int16_t) set, initializing the VLC fails. The reason is that the type of the symbol in the temporary array is an uint16_t and so comparing it to the symbol read from the VLC table will fail, because only the lower 16bits coincide. Said failure triggers an assert. Signed-off-by: Andreas Rheinhardt --- Found when playing around a bit with making the ClearVideo VLCs static. libavcodec/bitstream.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/bitstream.c b/libavcodec/bitstream.c index 39749c6092..a908c10980 100644 --- a/libavcodec/bitstream.c +++ b/libavcodec/bitstream.c @@ -129,7 +129,7 @@ static int alloc_table(VLC *vlc, int size, int use_static) typedef struct VLCcode { uint8_t bits; - uint16_t symbol; + VLC_TYPE symbol; /** codeword, with the first bit-to-be-read in the msb * (even if intended for a little-endian bitstream reader) */ uint32_t code;