Skip to content

Commit

Permalink
lzmainfo: Avoid integer overflow
Browse files Browse the repository at this point in the history
The MB output can overflow with huge numbers. Most likely these are
invalid lzma files anyway, but let's avoid garbage output.

Co-authored-by: Lasse Collin <[email protected]>
  • Loading branch information
stoeckmann and Larhzu committed Sep 16, 2024
1 parent 78355ae commit 9fe9acb
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/lzmainfo/lzmainfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ lzmainfo(const char *name, FILE *f)
printf("Unknown");
else
printf("%" PRIu64 " MB (%" PRIu64 " bytes)",
(uncompressed_size + 512 * 1024)
/ (1024 * 1024),
(uncompressed_size / 1024 + 512)
/ 1024,
uncompressed_size);

lzma_options_lzma *opt = filter.options;
Expand All @@ -160,7 +160,7 @@ lzmainfo(const char *name, FILE *f)
"Literal context bits (lc): %" PRIu32 "\n"
"Literal pos bits (lp): %" PRIu32 "\n"
"Number of pos bits (pb): %" PRIu32 "\n",
(opt->dict_size + 512 * 1024) / (1024 * 1024),
(opt->dict_size / 1024 + 512) / 1024,
my_log2(opt->dict_size), opt->lc, opt->lp, opt->pb);

free(opt);
Expand Down

0 comments on commit 9fe9acb

Please sign in to comment.