From 2766b28eea73b008c4dd7e9596b33179636f1b66 Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Thu, 10 Sep 2009 14:51:50 +0200 Subject: [PATCH] Fix #1364 and #1363 about compression buffer error. --- bacula/src/filed/restore.c | 18 +++++++++++++----- bacula/src/stored/bextract.c | 13 ++++++++++--- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/bacula/src/filed/restore.c b/bacula/src/filed/restore.c index e8d1ca609f..801ae45a6b 100644 --- a/bacula/src/filed/restore.c +++ b/bacula/src/filed/restore.c @@ -207,7 +207,7 @@ void do_restore(JCR *jcr) if (have_libz) { uint32_t compress_buf_size = jcr->buf_size + 12 + ((jcr->buf_size+999) / 1000) + 100; - jcr->compress_buf = (char *)bmalloc(compress_buf_size); + jcr->compress_buf = get_memory(compress_buf_size); jcr->compress_buf_size = compress_buf_size; } @@ -743,7 +743,7 @@ ok_out: } if (jcr->compress_buf) { - free(jcr->compress_buf); + free_pool_memory(jcr->compress_buf); jcr->compress_buf = NULL; jcr->compress_buf_size = 0; } @@ -967,10 +967,18 @@ bool decompress_data(JCR *jcr, char **data, uint32_t *length) */ compress_len = jcr->compress_buf_size; Dmsg2(200, "Comp_len=%d msglen=%d\n", compress_len, *length); - if ((stat=uncompress((Byte *)jcr->compress_buf, &compress_len, - (const Byte *)*data, (uLong)*length)) != Z_OK) { + while ((stat=uncompress((Byte *)jcr->compress_buf, &compress_len, + (const Byte *)*data, (uLong)*length)) == Z_BUF_ERROR) + { + /* The buffer size is too small, try with a bigger one */ + compress_len = jcr->compress_buf_size = jcr->compress_buf_size + jcr->compress_buf_size >> 1; + Dmsg2(200, "Comp_len=%d msglen=%d\n", compress_len, *length); + jcr->compress_buf = check_pool_memory_size(jcr->compress_buf, + compress_len); + } + if (stat != Z_OK) { Qmsg(jcr, M_ERROR, 0, _("Uncompression error on file %s. ERR=%s\n"), - jcr->last_fname, zlib_strerror(stat)); + jcr->last_fname, zlib_strerror(stat)); return false; } *data = jcr->compress_buf; diff --git a/bacula/src/stored/bextract.c b/bacula/src/stored/bextract.c index 1a8c67f542..5786a4c133 100644 --- a/bacula/src/stored/bextract.c +++ b/bacula/src/stored/bextract.c @@ -438,9 +438,16 @@ static bool record_cb(DCR *dcr, DEV_RECORD *rec) wbuf = rec->data; wsize = rec->data_len; } - compress_len = compress_buf_size; - if ((stat=uncompress((Bytef *)compress_buf, &compress_len, - (const Bytef *)wbuf, (uLong)wsize) != Z_OK)) { + + while ((stat=uncompress((Byte *)compress_buf, &compress_len, + (const Byte *)wbuf, (uLong)wsize)) == Z_BUF_ERROR) + { + /* The buffer size is too small, try with a bigger one */ + compress_len = compress_len + compress_len >> 1; + compress_buf = check_pool_memory_size(compress_buf, + compress_len); + } + if (stat != Z_OK) { Emsg1(M_ERROR, 0, _("Uncompression error. ERR=%d\n"), stat); extract = false; return true; -- 2.39.5