]> git.sur5r.net Git - bacula/bacula/blob - bacula/patches/3.0.2-zlib-buffer.patch
Tweak ActionOnPurge code
[bacula/bacula] / bacula / patches / 3.0.2-zlib-buffer.patch
1 commit 6a6cba0ab43be4ba5572b408c3c4fb79352a5273
2 Author: Eric Bollengier <eric@eb.homelinux.org>
3 Date:   Thu Sep 3 08:15:54 2009 +0200
4
5     Fix #1364 and #1363 about compression buffer error.
6
7 diff --git a/bacula/src/filed/restore.c b/bacula/src/filed/restore.c
8 index 808daec..a4ee03a 100644
9 --- a/bacula/src/filed/restore.c
10 +++ b/bacula/src/filed/restore.c
11 @@ -207,7 +207,7 @@ void do_restore(JCR *jcr)
12  
13     if (have_libz) {
14        uint32_t compress_buf_size = jcr->buf_size + 12 + ((jcr->buf_size+999) / 1000) + 100;
15 -      jcr->compress_buf = (char *)bmalloc(compress_buf_size);
16 +      jcr->compress_buf = get_memory(compress_buf_size);
17        jcr->compress_buf_size = compress_buf_size;
18     }
19  
20 @@ -802,7 +802,7 @@ ok_out:
21     }
22  
23     if (jcr->compress_buf) {
24 -      free(jcr->compress_buf);
25 +      free_pool_memory(jcr->compress_buf);
26        jcr->compress_buf = NULL;
27        jcr->compress_buf_size = 0;
28     }
29 @@ -1007,10 +1007,18 @@ bool decompress_data(JCR *jcr, char **data, uint32_t *length)
30      */
31     compress_len = jcr->compress_buf_size;
32     Dmsg2(200, "Comp_len=%d msglen=%d\n", compress_len, *length);
33 -   if ((stat=uncompress((Byte *)jcr->compress_buf, &compress_len,
34 -               (const Byte *)*data, (uLong)*length)) != Z_OK) {
35 +   while ((stat=uncompress((Byte *)jcr->compress_buf, &compress_len,
36 +                           (const Byte *)*data, (uLong)*length)) == Z_BUF_ERROR)
37 +   {
38 +      /* The buffer size is too small, try with a bigger one */
39 +      compress_len = jcr->compress_buf_size = jcr->compress_buf_size + jcr->compress_buf_size >> 1;
40 +      Dmsg2(200, "Comp_len=%d msglen=%d\n", compress_len, *length);
41 +      jcr->compress_buf = check_pool_memory_size(jcr->compress_buf,
42 +                                                 compress_len);
43 +   }
44 +   if (stat != Z_OK) {
45        Qmsg(jcr, M_ERROR, 0, _("Uncompression error on file %s. ERR=%s\n"),
46 -            jcr->last_fname, zlib_strerror(stat));
47 +           jcr->last_fname, zlib_strerror(stat));
48        return false;
49     }
50     *data = jcr->compress_buf;
51 diff --git a/bacula/src/stored/bextract.c b/bacula/src/stored/bextract.c
52 index 1a8c67f..5786a4c 100644
53 --- a/bacula/src/stored/bextract.c
54 +++ b/bacula/src/stored/bextract.c
55 @@ -438,9 +438,16 @@ static bool record_cb(DCR *dcr, DEV_RECORD *rec)
56              wbuf = rec->data;
57              wsize = rec->data_len;
58           }
59 -         compress_len = compress_buf_size;
60 -         if ((stat=uncompress((Bytef *)compress_buf, &compress_len,
61 -               (const Bytef *)wbuf, (uLong)wsize) != Z_OK)) {
62 +
63 +         while ((stat=uncompress((Byte *)compress_buf, &compress_len,
64 +                                 (const Byte *)wbuf, (uLong)wsize)) == Z_BUF_ERROR)
65 +         {
66 +            /* The buffer size is too small, try with a bigger one */
67 +            compress_len = compress_len + compress_len >> 1;
68 +            compress_buf = check_pool_memory_size(compress_buf,
69 +                                                  compress_len);
70 +         }
71 +         if (stat != Z_OK) {
72              Emsg1(M_ERROR, 0, _("Uncompression error. ERR=%d\n"), stat);
73              extract = false;
74              return true;