Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1nCP0E-0003HP-LQ for mharc-grub-devel@gnu.org; Tue, 25 Jan 2022 11:49:08 -0500 Received: from eggs.gnu.org ([209.51.188.92]:53352) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nCP09-0003FT-7a for grub-devel@gnu.org; Tue, 25 Jan 2022 11:49:01 -0500 Received: from smtp-relay-internal-0.canonical.com ([185.125.188.122]:33542) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nCP05-0000so-Ib for grub-devel@gnu.org; Tue, 25 Jan 2022 11:49:00 -0500 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 5729D3F197 for ; Tue, 25 Jan 2022 16:48:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1643129333; bh=8hrqIkmCubDy/o7mAv7/VbNNDAhj1nkzSkZ5sK118WY=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=NsuwawLNWmGcEGcKMg4DfC/C2qyQs7elHFP05Qfu5kKbwNYzFSS0L+zcGJEZJRxGj koGlX+wiQ/ArlqcxGy/FrTsKXfkgBPxOA+jCQ0JBzHiIPj2+JQBsrtrfLHT7fNVfsK Ddk+fM8FPhsFY5dE97x54nApDNBO2D4S75fE44nxj4XUJFq1kYucPzGpdHq+M0Hbl3 OIRJfNJ+JzNb6lSvKJqnO1QRlc9+pAAikFDQR+FDyP9TgRT8rKM5fgXvZvoBUFzWKX iN5f6xygqWksbs96ai8ICYDN3kBHoKow9Lnwt+Iobzme+1fn17zCNCyUYhPsrPaYDb 1BGZn3FX5/lbQ== Received: by mail-wr1-f70.google.com with SMTP id c10-20020adfa30a000000b001d79c73b64bso3319758wrb.1 for ; Tue, 25 Jan 2022 08:48:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=8hrqIkmCubDy/o7mAv7/VbNNDAhj1nkzSkZ5sK118WY=; b=qsvE6GyQzQpsLoTvJ3On35qW5vC6YvVM6Zd4BnFHFjoYQRPoenVDgYj8Qx11AyCF4d hLm6TQOL0Ejx+XbqAgEyYq67WDEm5l0qcIe/4UER+Cz3zkVfTGfvVMvzKZoC1Tj8ov07 pfK+p+lHHiOHKOVnrIe+JKNJYMnqpKqxg8x+1W2UUKVGAjAJxMEVhGz9Tl1YpI+S46/z ZG5gQ4e6NpJ3Gupi/wc8yk2/0z3J2Yi9Xv6I5oMaILiTSJRqMxiU907TeTIHObDjVsH5 v/RNamhBoGQxN/hqw/FnwkbbwAjKfcyu7Uo1QLxl5p/xMmN/eERPe0EwhNSXeUeri2JE DcLw== X-Gm-Message-State: AOAM5330dxUtvGCoU1NtYmbLCpXB2A3fQH4l0R/dgClx0SbpVRk3R4kq g6LOY3bZAv7ueQd7jcR138Z7SCD+qNhe/+OB2fZp0pAIua2j+d9cS3zlR8S4MezWq9AOiCeIhtS LtyPe1TjUOCvHxTytvBcXSac1mP3/ X-Received: by 2002:a05:6000:2aa:: with SMTP id l10mr9866673wry.470.1643129333025; Tue, 25 Jan 2022 08:48:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJz3XKnOulYr09jxwNJ3D8ZUZnnP5rWnfQldo7snMzaqpya86t/ahYPR9C0zqKNh7mraTHAT/A== X-Received: by 2002:a05:6000:2aa:: with SMTP id l10mr9866655wry.470.1643129332725; Tue, 25 Jan 2022 08:48:52 -0800 (PST) Received: from jak-t480s ([2a02:908:2816:fb20:7c06:b0d5:4590:ae2a]) by smtp.gmail.com with ESMTPSA id r13sm830832wmq.33.2022.01.25.08.48.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jan 2022 08:48:52 -0800 (PST) From: Julian Andres Klode To: grub-devel@gnu.org Cc: Julian Andres Klode Subject: [PATCH] zstd: Require at least 8 byte buffer in entropy_common Date: Tue, 25 Jan 2022 17:48:42 +0100 Message-Id: <20220125164842.1204920-1-julian.klode@canonical.com> X-Mailer: git-send-email 2.33.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=185.125.188.122; envelope-from=julian.klode@canonical.com; helo=smtp-relay-internal-0.canonical.com X-Spam_score_int: -45 X-Spam_score: -4.6 X-Spam_bar: ---- X-Spam_report: (-4.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.158, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Jan 2022 16:49:01 -0000 This fixes the build on s390x which was rightfully complaining that iend - 7 = buffer + 4 - 7 = buffer -3 is outside the array bounds. ../../grub-core/lib/zstd/entropy_common.c: In function ‘FSE_readNCount’: ../../grub-core/lib/zstd/entropy_common.c:121:28: error: array subscript -3 is outside array bounds of ‘char[4]’ [-Werror=array-bounds] 121 | if ((ip <= iend-7) || (ip + (bitCount>>3) <= iend-4)) { | ~~~~^~ ../../grub-core/lib/zstd/entropy_common.c:77:14: note: while referencing ‘buffer’ 77 | char buffer[4]; | ^~~~~~ ../../grub-core/lib/zstd/entropy_common.c:105:30: error: array subscript -1 is outside array bounds of ‘char[4]’ [-Werror=array-bounds] 105 | if (ip < iend-5) { | ~~~~^~ ../../grub-core/lib/zstd/entropy_common.c:77:14: note: while referencing ‘buffer’ 77 | char buffer[4]; | ^~~~~~ ../../grub-core/lib/zstd/entropy_common.c:150:28: error: array subscript -3 is outside array bounds of ‘char[4]’ [-Werror=array-bounds] 150 | if ((ip <= iend-7) || (ip + (bitCount>>3) <= iend-4)) { | ~~~~^~ ../../grub-core/lib/zstd/entropy_common.c:77:14: note: while referencing ‘buffer’ 77 | char buffer[4]; | ^~~~~~ This is fixed in more recent zstd versions in basically the same way, but the new versions needs more work to import. Signed-off-by: Julian Andres Klode --- grub-core/lib/zstd/entropy_common.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/grub-core/lib/zstd/entropy_common.c b/grub-core/lib/zstd/entropy_common.c index b12944e1d..834fa4b7d 100644 --- a/grub-core/lib/zstd/entropy_common.c +++ b/grub-core/lib/zstd/entropy_common.c @@ -72,9 +72,9 @@ size_t FSE_readNCount (short* normalizedCounter, unsigned* maxSVPtr, unsigned* t unsigned charnum = 0; int previous0 = 0; - if (hbSize < 4) { + if (hbSize < 8) { /* This function only works when hbSize >= 4 */ - char buffer[4]; + char buffer[8]; memset(buffer, 0, sizeof(buffer)); memcpy(buffer, headerBuffer, hbSize); { size_t const countSize = FSE_readNCount(normalizedCounter, maxSVPtr, tableLogPtr, @@ -83,7 +83,7 @@ size_t FSE_readNCount (short* normalizedCounter, unsigned* maxSVPtr, unsigned* t if (countSize > hbSize) return ERROR(corruption_detected); return countSize; } } - assert(hbSize >= 4); + assert(hbSize >= 8); /* init */ memset(normalizedCounter, 0, (*maxSVPtr+1) * sizeof(normalizedCounter[0])); /* all symbols not present in NCount have a frequency of 0 */ -- 2.33.1