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;
}
}
if (jcr->compress_buf) {
- free(jcr->compress_buf);
+ free_pool_memory(jcr->compress_buf);
jcr->compress_buf = NULL;
jcr->compress_buf_size = 0;
}
*/
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;
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;