8000 Fixed the calculation for the max compressed size of Xpress Huffman f… · coderforlife/ms-compress@60ef385 · GitHub
[go: up one dir, main page]

Skip to content

Commit 60ef385

Browse files
committed
Fixed the calculation for the max compressed size of Xpress Huffman for the last chunk.
1 parent 461ede1 commit 60ef385

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/xpress_huff_compress.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
typedef XpressDictionary<MAX_OFFSET, CHUNK_SIZE> Dictionary;
4444
typedef HuffmanEncoder<HUFF_BITS_MAX, SYMBOLS> Encoder;
4545

46-
size_t xpress_huff_max_compressed_size(size_t in_len) { return in_len + 4 + (HALF_SYMBOLS + 2) + (HALF_SYMBOLS + 2) * (in_len / CHUNK_SIZE); }
46+
size_t xpress_huff_max_compressed_size(size_t in_len) { return in_len + 32 + (HALF_SYMBOLS + 2) + (HALF_SYMBOLS + 2) * (in_len / CHUNK_SIZE); }
4747

4848

4949
////////////////////////////// Compression Functions ///////////////////////////////////////////////
@@ -303,12 +303,12 @@ ENTRY_POINT MSCompStatus xpress_huff_compress(const_bytes in, size_t in_len, byt
303303
////////// Guarantee Max Compression Size //////////
304304
// This is required to guarantee max compressed size
305305
// It is very rare that it is used (mainly medium-high uncompressible data)
306-
if (UNLIKELY(comp_len > in_len+6)) // +4 to 5 for alignment and end-of-stream
306+
if (UNLIKELY(comp_len > in_len+34)) // +34 for alignment and end of stream (because it causes a different symbol to need 9 bits)
307307
{
308308
buf_len = xh_compress_no_matching(in, in_len, true, buf, symbol_counts);
309309
lens = encoder.CreateCodesSlow(symbol_counts);
310310
comp_len = xh_calc_compressed_len_no_matching(lens, symbol_counts);
311-
assert(comp_len <= in_len+6);
311+
assert(comp_len <= in_len+34);
312312
}
313313

314314
////////// Output Huffman prefix codes as lengths and Encode compressed data //////////

0 commit comments

Comments
 (0)
0