From c9812a5d413382b81552979b10e5c478b3721316 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Tue, 18 Dec 2012 22:24:52 -0600 Subject: [PATCH 1/1] Fix xpress_compress() minimum size --- src/xpress-compress.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/xpress-compress.c b/src/xpress-compress.c index 77df5279..2b3a6a6e 100644 --- a/src/xpress-compress.c +++ b/src/xpress-compress.c @@ -169,8 +169,14 @@ int xpress_compress(const void *__uncompressed_data, unsigned uncompressed_len, /* XPRESS requires 256 bytes of overhead for the Huffman tables, so it's * impossible cannot compress 256 bytes or less of data to less than the - * input size. */ - if (uncompressed_len <= XPRESS_NUM_SYMBOLS / 2) + * input size. + * + * +1 to take into account that the buffer for compressed data is 1 byte + * smaller than the buffer for uncompressed data. + * + * +4 to take into account that init_output_bitstream() requires at + * least 4 bytes of data. */ + if (uncompressed_len < XPRESS_NUM_SYMBOLS / 2 + 1 + 4) return 1; ZERO_ARRAY(freq_tab); -- 2.43.0