From 6a6cba0ab43be4ba5572b408c3c4fb79352a5273 Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Thu, 3 Sep 2009 08:15:54 +0200 Subject: [PATCH] Fix #1364 and #1363 about compression buffer error. --- bacula/src/filed/restore.c | 18 +++++++++++++----- bacula/src/stored/bextract.c | 13 ++++++++++--- bacula/technotes | 2 ++ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/bacula/src/filed/restore.c b/bacula/src/filed/restore.c index 808daec84b..a4ee03a842 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; } @@ -802,7 +802,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; } @@ -1007,10 +1007,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; diff --git a/bacula/technotes b/bacula/technotes index 718907cb19..ce88f34648 100644 --- a/bacula/technotes +++ b/bacula/technotes @@ -2,6 +2,8 @@ General: +03Sep09 +ebl Fix #1364 and #1363 about compression buffer error. 01Sep09 kes Many debug code fixes in regression scripts kes Update tape tests for hardware certification -- 2.39.5