erofs-utils: lib: fix `INTEGER_OVERFLOW`
Coverity-id: 569453
Fixes: 341d23a878a2 ("erofs-utils: mkfs: speed up uncompressed data handling")
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20250708021722.768644-4-hsiangkao@linux.alibaba.com
diff --git a/lib/compress.c b/lib/compress.c
index fdcc70f..a57bb6a 100644
--- a/lib/compress.c
+++ b/lib/compress.c
@@ -579,18 +579,15 @@
if (len <= ctx->pclustersize) {
if (!final || !len)
return 1;
- if (may_packing) {
- if (inode->fragment_size && !ictx->fix_dedupedfrag) {
- ctx->pclustersize = roundup(len, blksz);
- goto fix_dedupedfrag;
- }
- e->length = len;
+ if (may_packing && inode->fragment_size && !ictx->fix_dedupedfrag) {
+ ctx->pclustersize = roundup(len, blksz);
+ goto fix_dedupedfrag;
+ }
+ e->length = len;
+ if (may_packing)
goto frag_packing;
- }
- if (!may_inline && len <= blksz) {
- e->length = len;
+ if (!may_inline && len <= blksz)
goto nocompression;
- }
}
e->length = min(len, cfg.c_max_decompressed_extent_bytes);
@@ -629,7 +626,7 @@
} else {
may_inline = false;
may_packing = false;
- e->length = min_t(u32, e->length, ret);
+ e->length = min_t(u32, e->length, ctx->pclustersize);
nocompression:
if (cfg.c_dedupe)
ret = write_uncompressed_block(ctx, len, dst);