The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Felix Handte <felixh@meta.com>
To: Ilya Krutskih <devsec@tpz.ru>, Nick Terrell <terrelln@fb.com>
Cc: David Sterba <dsterba@suse.com>,
	linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org,
	stable@vger.kernel.org
Subject: Re: [PATCH v3] zstd: fixed possible 'rtbTable' underflow in FSE_normalizeCount()
Date: Tue, 13 Jan 2026 13:58:40 -0500	[thread overview]
Message-ID: <dfdb2c31-3cdc-43d3-9e5f-0356cf4c1a0d@meta.com> (raw)
In-Reply-To: <20251211171950.852001-1-devsec@tpz.ru>

Ilya, can you share any context for this patch? Do you have any evidence 
that `proba` can be negative?

A discussion was just started about this patch on the zstd repo [0]. I'm 
happy to discuss this here or there, whichever is more convenient.

But to my first pass inspection, this seems to be protecting an 
impossible situation. (Separately: if it could happen, the correct 
behavior would to catch it and return an error, not just skip it like 
this patch proposes.)

Thanks,
Felix

[0] https://github.com/facebook/zstd/issues/4567

On 12/11/25 12:19 PM, Ilya Krutskih wrote:
> 'rtbTable' may be underflowed because 'proba' is used without
> checking for a non-negative as index of rtbTable[].
> 
> Add check: proba >= 0
> 
> Cc: stable@vger.kernel.org # v5.10+
> Fixes: e0c1b49f5b67 ("lib: zstd: Upgrade to latest upstream zstd version 1.4.10")
> Signed-off-by: Ilya Krutskih <devsec@tpz.ru>
> ---
>   lib/zstd/compress/fse_compress.c | 7 ++++---
>   1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/zstd/compress/fse_compress.c b/lib/zstd/compress/fse_compress.c
> index 44a3c10becf2..6b83f8bc943a 100644
> --- a/lib/zstd/compress/fse_compress.c
> +++ b/lib/zstd/compress/fse_compress.c
> @@ -492,9 +492,10 @@ size_t FSE_normalizeCount (short* normalizedCounter, unsigned tableLog,
>                   stillToDistribute--;
>               } else {
>                   short proba = (short)((count[s]*step) >> scale);
> -                if (proba<8) {
> -                    U64 restToBeat = vStep * rtbTable[proba];
> -                    proba += (count[s]*step) - ((U64)proba<<scale) > restToBeat;
> +		if ((proba >= 0) && (proba < 8)) {
> +			U64 restToBeat = vStep * rtbTable[proba];
> +
> +			proba += (count[s]*step) - ((U64)proba<<scale) > restToBeat;
>                   }
>                   if (proba > largestP) { largestP=proba; largest=s; }
>                   normalizedCounter[s] = proba;


      reply	other threads:[~2026-01-13 18:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-11 17:19 [PATCH v3] zstd: fixed possible 'rtbTable' underflow in FSE_normalizeCount() Ilya Krutskih
2026-01-13 18:58 ` Felix Handte [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=dfdb2c31-3cdc-43d3-9e5f-0356cf4c1a0d@meta.com \
    --to=felixh@meta.com \
    --cc=devsec@tpz.ru \
    --cc=dsterba@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lvc-project@linuxtesting.org \
    --cc=stable@vger.kernel.org \
    --cc=terrelln@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox