From 2458a651b78de05fbd09c8aad627c1b97a8ac9b2 Mon Sep 17 00:00:00 2001 From: Roy Oursler Date: Fri, 12 Oct 2018 14:52:58 -0700 Subject: [PATCH] igzip: Increase overestimate of compressed data size in igzip_perf Change-Id: I16adcd817737f71fc59dac585c65c73eb3397d99 Signed-off-by: Roy Oursler --- igzip/igzip_perf.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/igzip/igzip_perf.c b/igzip/igzip_perf.c index 0f859b7..4b3175b 100644 --- a/igzip/igzip_perf.c +++ b/igzip/igzip_perf.c @@ -48,6 +48,11 @@ #define COMPRESSION_QUEUE_LIMIT 32 #define UNSET -1 +/* Limit output buffer size to 2 Gigabytes. Since stream->avail_out is a + * uint32_t and there is no logic for handling an overflowed output buffer in + * the perf test, this define must be less then 4 Gigabytes */ +#define MAX_COMPRESS_BUF_SIZE (1 << 31) + int level_size_buf[10] = { #ifdef ISAL_DEF_LVL0_DEFAULT ISAL_DEF_LVL0_DEFAULT, @@ -482,6 +487,7 @@ int main(int argc, char *argv[]) unsigned char *compressbuf, *decompbuf, *filebuf; int i, c, ret = 0; uint64_t decompbuf_size, compressbuf_size; + uint64_t block_count; struct compress_strategy compression_queue[COMPRESSION_QUEUE_LIMIT]; @@ -635,12 +641,22 @@ int main(int argc, char *argv[]) exit(0); } - compressbuf_size = 2 * info.file_size; + block_count = 1; + if (info.flush_type > 0) + block_count = (info.file_size + info.inblock_size - 1) / info.inblock_size; + + /* Way overestimate likely compressed size to handle bad type 0 and + * small block_size case */ + compressbuf_size = block_count * ISAL_DEF_MAX_HDR_SIZE + 2 * info.file_size; + if (compressbuf_size >= MAX_COMPRESS_BUF_SIZE) + compressbuf_size = MAX_COMPRESS_BUF_SIZE; + compressbuf = malloc(compressbuf_size); if (compressbuf == NULL) { fprintf(stderr, "Can't allocate input buffer memory\n"); exit(0); } + decompbuf = malloc(decompbuf_size); if (decompbuf == NULL) { fprintf(stderr, "Can't allocate output buffer memory\n");