Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1nCS88-0002uU-Do for mharc-grub-devel@gnu.org; Tue, 25 Jan 2022 15:09:28 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60984) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nCS86-0002td-7E for grub-devel@gnu.org; Tue, 25 Jan 2022 15:09:26 -0500 Received: from [2607:f8b0:4864:20::1029] (port=35775 helo=mail-pj1-x1029.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nCS83-0007db-7J for grub-devel@gnu.org; Tue, 25 Jan 2022 15:09:25 -0500 Received: by mail-pj1-x1029.google.com with SMTP id w12-20020a17090a528c00b001b276aa3aabso2844956pjh.0 for ; Tue, 25 Jan 2022 12:09:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientek-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=z3bRT564CDRhFYA0HpADx9WOFTCVRloqlpcvtzCCL7U=; b=gyHeZThboXTPFlYcjsfyL7jEvAx9glWaFpPA+3IJwtQuETJ8xhKh5UKUQX22PRE4TL PBtbBpM0xQGntp+EqFNue9OVuSYSmdhxHGPF9pyt7DVabfPy3WvuOhits1pnK/WMJIys 3YLNB3aGDNDhlcFTAN456aFGZgByWHgSahzNCJGKXaRBwu96aH7s3gL2Uk2Lnd0MBwKz Y457NU9mbs+a3OFpf7PwCfF5GzAu/hkK/v/AG2LWxI25/T6YV41duHgRgKNtAJsbY/3u vcwl5jE03LYuNLHFHdC8UOcJOwz4xl8PhvyNZFHsG3yG5KZVHk8DHcCaeUQISmGkh1LQ 2ZEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=z3bRT564CDRhFYA0HpADx9WOFTCVRloqlpcvtzCCL7U=; b=mSb+VtNPr9Qx/BSpjvB0lvKCai8xnMsB0RPIlp7FT8eUxRCK1+XJxyIYMaIQ8/DZf3 8j8ssXLpf525OfkZb+H3kCBwXHgJqSozqTf0BvgoFOA4WO6nYSAbGiToqdHAkzTEcmaD GYo47TMoQuveqL2AG4/1CIs5l+rzpEuPLXqiSwAEA6vD+EICsYFO49T4VpeCXXcPNRcd 113W9sbrF9jbKWm+nIRPfDLpNc9mo4HzX6BTezQR4624Zqw5VZPzzV5MUZnmWhp5WJmS nEJSfMQvWMVPhlbxWBp4S+RNQTGNxHSe4JGTWlK8kzfXagxy1RkaW2W0yeXklPSu15v7 b8oQ== X-Gm-Message-State: AOAM533BFAVTqRPsxa1H5CKRPM19eFmopH3UmHGuZgOIc2V3KrKs1djX DxeBwOTxO8a3wPFpy2PzpYRHjw== X-Google-Smtp-Source: ABdhPJxdMCNraiKjyH0gi5IAeCjz15Y/+wPCHIQKSLu6SwVDlpbKhsNQJv2aOvZUAs8Mo9VVWE6w5w== X-Received: by 2002:a17:902:ab15:b0:14b:7b4c:91cc with SMTP id ik21-20020a170902ab1500b0014b7b4c91ccmr3376707plb.146.1643141360643; Tue, 25 Jan 2022 12:09:20 -0800 (PST) Received: from crass-HP-ZBook-15-G2 (yal.riseup.net. [199.58.83.9]) by smtp.gmail.com with ESMTPSA id n34sm18719631pfv.209.2022.01.25.12.08.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jan 2022 12:09:05 -0800 (PST) Date: Tue, 25 Jan 2022 14:06:30 -0600 From: Glenn Washburn To: Julian Andres Klode Cc: The development of GNU GRUB Subject: Re: [PATCH] zstd: Require at least 8 byte buffer in entropy_common Message-ID: <20220125140630.52eeece4@crass-HP-ZBook-15-G2> In-Reply-To: <20220125164842.1204920-1-julian.klode@canonical.com> References: <20220125164842.1204920-1-julian.klode@canonical.com> Reply-To: development@efficientek.com X-Mailer: Claws Mail 3.18.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::1029 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::1029; envelope-from=development@efficientek.com; helo=mail-pj1-x1029.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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 20:09:26 -0000 On Tue, 25 Jan 2022 17:48:42 +0100 Julian Andres Klode wrote: > This fixes the build on s390x which was rightfully complaining that > iend - 7 =3D buffer + 4 - 7 =3D buffer -3 is outside the array bounds. >=20 > ../../grub-core/lib/zstd/entropy_common.c: In function =E2=80=98FSE_readN= Count=E2=80=99: > ../../grub-core/lib/zstd/entropy_common.c:121:28: error: array subscript = -3 is outside array bounds of =E2=80=98char[4]=E2=80=99 [-Werror=3Darray-bo= unds] > 121 | if ((ip <=3D iend-7) || (ip + (bitCount>>3) <=3D iend= -4)) { > | ~~~~^~ > ../../grub-core/lib/zstd/entropy_common.c:77:14: note: while referencing = =E2=80=98buffer=E2=80=99 > 77 | char buffer[4]; > | ^~~~~~ > ../../grub-core/lib/zstd/entropy_common.c:105:30: error: array subscript = -1 is outside array bounds of =E2=80=98char[4]=E2=80=99 [-Werror=3Darray-bo= unds] > 105 | if (ip < iend-5) { > | ~~~~^~ > ../../grub-core/lib/zstd/entropy_common.c:77:14: note: while referencing = =E2=80=98buffer=E2=80=99 > 77 | char buffer[4]; > | ^~~~~~ > ../../grub-core/lib/zstd/entropy_common.c:150:28: error: array subscript = -3 is outside array bounds of =E2=80=98char[4]=E2=80=99 [-Werror=3Darray-bo= unds] > 150 | if ((ip <=3D iend-7) || (ip + (bitCount>>3) <=3D iend= -4)) { > | ~~~~^~ > ../../grub-core/lib/zstd/entropy_common.c:77:14: note: while referencing = =E2=80=98buffer=E2=80=99 > 77 | char buffer[4]; > | ^~~~~~ >=20 > This is fixed in more recent zstd versions in basically the same way, > but the new versions needs more work to import. >=20 > Signed-off-by: Julian Andres Klode > --- > grub-core/lib/zstd/entropy_common.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) >=20 > diff --git a/grub-core/lib/zstd/entropy_common.c b/grub-core/lib/zstd/ent= ropy_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, unsign= ed* maxSVPtr, unsigned* t > unsigned charnum =3D 0; > int previous0 =3D 0; > =20 > - if (hbSize < 4) { > + if (hbSize < 8) { > /* This function only works when hbSize >=3D 4 */ I can't comment on the change itself, but shouldn't this comment be changed as well? Glenn > - char buffer[4]; > + char buffer[8]; > memset(buffer, 0, sizeof(buffer)); > memcpy(buffer, headerBuffer, hbSize); > { size_t const countSize =3D FSE_readNCount(normalizedCounter,= maxSVPtr, tableLogPtr, > @@ -83,7 +83,7 @@ size_t FSE_readNCount (short* normalizedCounter, unsign= ed* maxSVPtr, unsigned* t > if (countSize > hbSize) return ERROR(corruption_detected); > return countSize; > } } > - assert(hbSize >=3D 4); > + assert(hbSize >=3D 8); > =20 > /* init */ > memset(normalizedCounter, 0, (*maxSVPtr+1) * sizeof(normalizedCounte= r[0])); /* all symbols not present in NCount have a frequency of 0 */