From patchwork Sat Sep 26 10:27: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: 22630 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:c650:0:0:0:0:0 with SMTP id k77csp1723257ybf; Sat, 26 Sep 2020 03:38:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjLS2oskjEc4CABxR1vL0XTo29wWkvQmBD2BtJRBPFhyECZ37J5JomPFL/EXQiMaaikpHC X-Received: by 2002:adf:e852:: with SMTP id d18mr9535179wrn.40.1601116686599; Sat, 26 Sep 2020 03:38:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601116686; cv=none; d=google.com; s=arc-20160816; b=pxOBy5PRVOHyDceTHft+hzk5xSyzy4AqSTZ9kN33WZgU+IPZ4OPROKKkjhuZH9xDPf mkUazpVlXjs7aQSJ2SU6GR/qpr0iZ9f4YMGxbrDCe4ss+H8Uhrkl+NZU7Xm3MUdrotwQ AQQAnM2xFVez5JbUnqTZCa4U9HFswl1TiuhwJv3zZc8WpDng0kxtSDw7EmX9XCYIlRag NjadOmt3J4ZOL0ne96K5nOi35JQ2wxzwxYcJ0yOqclmInTG37lnfEWZQCvUAMgSUA5g1 uW1f66+BN2tCNrTfv/dJw4Skgx3EvqM9c26YeMWBXtQTsduNL8LDFurAeEGfVxzQ+f44 D2CA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=EzDLyKtJJhLWR+tHu8WAvc0RI83G0VOIRgVEE+VVAqQ=; b=wdqQ8P3aUa/T+fFHRiYH1sH2SV8CdrOjrsGQv/20MHKMigTnUm49CJhG6H/7IvC6zB voofeVq6SAZrRth6paVwFJjRr4vrhSJ0PpviH5RaktkW350Da5VhuG7SxXJqvjuPlH+v TshkfFhLeSbh4c5QVCfH8J5gHUgyZnpdAIAUa24mD3dH6g69I0DqYvivYhgNyTAeHWtj GuCmRzJ7nznTFdSv0DLp+XF4ZaytxdwhPRaZxwOEehE5EdyUy0NHzzfxL1Gu28NjjRd2 kqUPNJZbFGhi6JReHuzUVtXK16BbPTocIjGatMrs3WFMagE3TUKOjg3mxaIkKvhlw2Lx rYDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=KW+ljCR+; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id o17si5598641wrp.82.2020.09.26.03.38.06; Sat, 26 Sep 2020 03:38:06 -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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=KW+ljCR+; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2D3FB68B86F; Sat, 26 Sep 2020 13:38:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1A73A6883D0 for ; Sat, 26 Sep 2020 13:37:57 +0300 (EEST) Received: by mail-wm1-f66.google.com with SMTP id b79so1879023wmb.4 for ; Sat, 26 Sep 2020 03:37:57 -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=HFoY4yfagmhajYWQNftN4u96sYQAzJO88WGqAq/APOY=; b=KW+ljCR+7fqZljGIwVjmFgZNd5KrFGH/GkIJRbmSdld+LapEnnS4Dzta/KduRUfrNF 6fWItXU6loTskxpj0mHiF/mguNJmnVuVdA+GnoxiXJnoWwDA7IGZlN96eIocL7mUBKku xecuWZ8nFE4c9EDuAgFwZEru6i/9awPDudQWECLdyWkPvz8UOJOgpua4gIv68TqpUEoj nZfyY/j0GB+CMj68cBnt+oG7hcH/Mibo4ugj14hiiKvdKcerHthJLp0Bbr5ndsERWhKg Hx2jELEI8yzc2Zx9S8R24XnwSR/UwGkD0fsu3mnvl+ZDFglURuys7getTiGGhlk7g+uh TX1g== 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=HFoY4yfagmhajYWQNftN4u96sYQAzJO88WGqAq/APOY=; b=F6RQ6MnOxMYmEQchoUDHmoAj3ykrOYhwUPdspPQslmCXFDugq43BAKHwem0NMBVGou TwNLesfSkY9vPshsu39g71NUzF3UslMyBTdxonYZKhUMysnTqpBrh360xqqiqh/QUNM5 PmMUhwSqh0+SF4hOqhzlLZoGhRlYjm7zA93JfdUNX9NSn4TStfKnzHllppkT+2NeyeDJ 0INFKMXfD9zp86mpMvB5VPXESXwMTs5DN6LAMfS/LocUfA/lNOw/11P5AEqF1V1ugWkQ ZR184uhce4qIxkhH/xBTXZO1UjglEBKOi+jeZZm0GNTR4RZ/VU5F2EFG5elAb5V6DJ3F DgIA== X-Gm-Message-State: AOAM533KzBtD9PObteMqqwS12CAfcNhtD/knjSbxDLzIdNkyyySvjXIJ gZS5NOaitNmU3x8uFI2hYeQ+6r6OPgc= X-Received: by 2002:a1c:9894:: with SMTP id a142mr1943852wme.167.1601116202251; Sat, 26 Sep 2020 03:30:02 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id k8sm6064867wrl.42.2020.09.26.03.30.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Sep 2020 03:30:01 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 26 Sep 2020 12:27:49 +0200 Message-Id: <20200926102804.228089-10-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> References: <20200926102804.228089-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 10/25] avcodec/magicyuv: Fix building Huffman table 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" X-TUID: SuoPcKXXSjLK Content-Length: 2379 The MagicYUV format stores Huffman tables in its bitstream by coding the length of a given symbol; it does not code the actual code directly, instead this is to be inferred by the rule that a symbol is to the left of every shorter symbol in the Huffman tree and that for symbols of the same length the symbol is ascending from left to right. With one exception, this is also what our decoder did. The exception only matters when there are codes of length 32, because in this case the first symbol of this length did not get the code 0, but 1; e.g. if there were exactly two nodes of length 32, then they would get assigned the codes 1 and 2 and a node of length 31 will get the 31-bit code 1 which is a prefix of the 32 bit code 2, making the Huffman table invalid. On the other hand, if there were only one symbol with the length 32, the earlier code would accept this un-Huffman-tree. Signed-off-by: Andreas Rheinhardt --- libavcodec/magicyuv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c index 1b3f4cfc6b..17dea69d76 100644 --- a/libavcodec/magicyuv.c +++ b/libavcodec/magicyuv.c @@ -86,7 +86,7 @@ static int huff_build(HuffEntry he[], VLC *vlc, int nb_elems) AV_QSORT(he, nb_elems, HuffEntry, huff_cmp_len); - code = 1; + code = 0; for (unsigned i = 0; i < nb_elems; i++) { he[i].code = code >> (32 - he[i].len); code += 0x80000000u >> (he[i].len - 1);