ref: 35fa4b6cf5b728cde8257605e4a55bf21e2bdda4
parent: 5735eaec8cbd472854096b9d70dbb96e4e09e829
author: Mans Rullgard <mans@mansr.com>
date: Sat Apr 28 15:06:58 EDT 2018
hcom: fix writing absurdly large files The bit size of the compressed output might overflow 32 bits. Use a 64-bit type instead.
--- a/src/hcom.c
+++ b/src/hcom.c
@@ -352,6 +352,7 @@
long codes[256], codesize[256];
dictent newdict[511];
int i, sample, j, k, d, l, frequcount;
+ int64_t csize;
sample = *datafork;
memset(frequtable, 0, sizeof(frequtable));
@@ -407,10 +408,10 @@
}
dictsize = p->de - newdict;
makecodes(0, 0, 0, 1, newdict, codes, codesize);
- l = 0;
+ csize = 0;
for (i = 0; i < 256; i++)
- l += frequtable[i] * codesize[i];
- l = (((l + 31) >> 5) << 2) + 24 + dictsize * 4;
+ csize += frequtable[i] * codesize[i];
+ l = (((csize + 31) >> 5) << 2) + 24 + dictsize * 4;
lsx_debug(" Original size: %6d bytes", *dl);
lsx_debug("Compressed size: %6d bytes", l);
datafork = lsx_malloc((size_t)l);