From: Ilya Krutskih <devsec@tpz.ru>
To: Nick Terrell <terrelln@fb.com>
Cc: Ilya Krutskih <devsec@tpz.ru>, David Sterba <dsterba@suse.com>,
<linux-kernel@vger.kernel.org>, <lvc-project@linuxtesting.org>,
<stable@vger.kernel.org>
Subject: [PATCH v3] zstd: fixed possible 'rtbTable' underflow in FSE_normalizeCount()
Date: Thu, 11 Dec 2025 17:19:49 +0000 [thread overview]
Message-ID: <20251211171950.852001-1-devsec@tpz.ru> (raw)
'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;
--
2.43.0
next reply other threads:[~2025-12-11 17:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-11 17:19 Ilya Krutskih [this message]
2026-01-13 18:58 ` [PATCH v3] zstd: fixed possible 'rtbTable' underflow in FSE_normalizeCount() Felix Handte
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=20251211171950.852001-1-devsec@tpz.ru \
--to=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