]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/filed/restore.c
Fix #1364 and #1363 about compression buffer error.
[bacula/bacula] / bacula / src / filed / restore.c
index 808daec84b14a4f5b3867cf85888134df2d57b68..a4ee03a8420849e23b46c04e4205a71684f20415 100644 (file)
@@ -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;