Skip to content

Commit

Permalink
fix compression module bugs
Browse files Browse the repository at this point in the history
* proper error messages on compress
* correct buffer size aproximation on gzip compress(10% + 12)
* fix bug on decompression
  • Loading branch information
ionutrazvanionita committed Oct 5, 2015
1 parent 76e9809 commit ca3895d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions modules/compression/compression.c
Expand Up @@ -1337,7 +1337,7 @@ int mc_compress_cb(char** buf_p, void* param, int type, int* olen)
bufcompressed.len = (int)temp;

if (check_zlib_rc(rc)) {
LM_ERR("Compression failed\n");
LM_ERR("Body compression failed\n");
goto free_mem_full;
}
}
Expand All @@ -1359,7 +1359,7 @@ int mc_compress_cb(char** buf_p, void* param, int type, int* olen)
hdr_bufcompressed.len = temp;

if (check_zlib_rc(rc)) {
LM_ERR("Compression failed\n");
LM_ERR("Header compression failed\n");
goto free_mem_full;
}
}
Expand All @@ -1375,7 +1375,7 @@ int mc_compress_cb(char** buf_p, void* param, int type, int* olen)
mc_level);

if (check_zlib_rc(rc)) {
LM_ERR("Compression failed\n");
LM_ERR("Body compression failed\n");
goto free_mem_full;
}

Expand All @@ -1392,7 +1392,7 @@ int mc_compress_cb(char** buf_p, void* param, int type, int* olen)
mc_level);

if (check_zlib_rc(rc)) {
LM_ERR("Compression failed\n");
LM_ERR("Header compression failed\n");
goto free_mem_full;
}
hdr_bufcompressed.s = hdr_out.s;
Expand Down Expand Up @@ -1868,8 +1868,8 @@ static int mc_decompress(struct sip_msg* msg)
hdr_vec[1]->body.len
);
} else if (hdr_vec[1]) {
b64_decode.s = hdr_vec[1]->body.s;
b64_decode.len = hdr_vec[1]->body.len;
hdr_b64_decode.s = hdr_vec[1]->body.s;
hdr_b64_decode.len = hdr_vec[1]->body.len;
}

switch (hdrs_algo) {
Expand All @@ -1885,7 +1885,7 @@ static int mc_decompress(struct sip_msg* msg)
uncomp_hdrs.len = temp;

if (check_zlib_rc(rc)) {
LM_ERR("decompression failed\n");
LM_ERR("header decompression failed\n");
return -1;
}
break;
Expand All @@ -1897,7 +1897,7 @@ static int mc_decompress(struct sip_msg* msg)
&temp);

if (check_zlib_rc(rc)) {
LM_ERR("decompression failed\n");
LM_ERR("header decompression failed\n");
return -1;
}

Expand All @@ -1921,7 +1921,7 @@ static int mc_decompress(struct sip_msg* msg)
(unsigned long)b64_decode.len);

if (check_zlib_rc(rc)) {
LM_ERR("decompression failed\n");
LM_ERR("body decompression failed\n");
return -1;
}

Expand All @@ -1937,7 +1937,7 @@ static int mc_decompress(struct sip_msg* msg)
&temp);

if (check_zlib_rc(rc)) {
LM_ERR("decompression failed\n");
LM_ERR("body decompression failed\n");
return -1;
}

Expand Down
4 changes: 2 additions & 2 deletions modules/compression/gz_helpers.c
Expand Up @@ -72,9 +72,9 @@ int gzip_compress(unsigned char* in, unsigned long ilen, str* out, unsigned long
return rc;
}

/* zlib doc states that dest buffer size must be 0.1% +12 larger than
/* zlib doc states that dest buffer size must be 10% +12 larger than
the input buffer */
neededSize = (int)((float)ilen * 1.01 + 12);
neededSize = (int)((float)ilen * 1.1 + 12);

if (!out->s) {
out->s = pkg_malloc(neededSize);
Expand Down

0 comments on commit ca3895d

Please sign in to comment.