From: Nithurshen <nithurshen@gmail.com>
To: linux-erofs@lists.ozlabs.org
Cc: hsiangkao@kernel.org, Nithurshen <nithurshen@gmail.com>
Subject: [PATCH] erofs-utils: lib: fix undefined behavior in zstd dict_size bit shift
Date: Sun, 22 Feb 2026 10:32:19 +0530 [thread overview]
Message-ID: <20260222050219.27511-1-nithurshen@gmail.com> (raw)
cppcheck static analysis flags that shifting the signed 32-bit literal
`1` by `ilog2(dict_size)` can lead to undefined behavior if the shift
amount reaches or exceeds 31.
This patch casts the literal to `1ULL` to ensure the shift operates
safely on an unsigned 64-bit integer, preventing potential overflows
on different architectures.
Signed-off-by: Nithurshen <nithurshen@gmail.com>
---
lib/compressor_libzstd.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/compressor_libzstd.c b/lib/compressor_libzstd.c
index c475077..f47635e 100644
--- a/lib/compressor_libzstd.c
+++ b/lib/compressor_libzstd.c
@@ -123,10 +123,10 @@ static int erofs_compressor_libzstd_setdictsize(struct erofs_compress *c,
} else {
dict_size = min_t(u32, Z_EROFS_ZSTD_MAX_DICT_SIZE,
pclustersize_max << 3);
- dict_size = 1 << ilog2(dict_size);
+ dict_size = 1ULL << ilog2(dict_size);
}
}
- if (dict_size != 1 << ilog2(dict_size) ||
+ if (dict_size != 1ULL << ilog2(dict_size) ||
dict_size > Z_EROFS_ZSTD_MAX_DICT_SIZE) {
erofs_err("invalid dictionary size %u", dict_size);
return -EINVAL;
--
2.51.0
next reply other threads:[~2026-02-22 5:03 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-22 5:02 Nithurshen [this message]
2026-02-22 7:18 ` [PATCH] erofs-utils: lib: fix undefined behavior in zstd dict_size bit shift Yifan Zhao
2026-02-22 8:06 ` [PATCH v2] " Nithurshen
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=20260222050219.27511-1-nithurshen@gmail.com \
--to=nithurshen@gmail.com \
--cc=hsiangkao@kernel.org \
--cc=linux-erofs@lists.ozlabs.org \
/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