Commit 54eb789e authored by Ghislain MARY's avatar Ghislain MARY

Really fix body handler decompression bug.

parent baf78cef
......@@ -323,6 +323,12 @@ int belle_sip_memory_body_handler_unapply_encoding(belle_sip_memory_body_handler
ret = inflate(&strm, Z_NO_FLUSH);
switch (ret) {
case Z_OK:
/* Error handling for truncated input buffer. Z_STREAM_END is not returned but there is no further input content */
if (strm.avail_out > 0) {
belle_sip_error("%s: truncated compressed body. Cannot uncompress it...", __FUNCTION__);
return -1;
}
break;
case Z_STREAM_END:
// Everything is ok, continue
break;
......
......@@ -309,11 +309,29 @@ static void test_presence_marshal(void) {
belle_sip_object_unref(mpbh);
}
static void test_compressed_body(void) {
belle_sip_memory_body_handler_t *mbh = belle_sip_memory_body_handler_new_copy_from_buffer((void *)parts_content[0], strlen(parts_content[0]), NULL, NULL);
belle_sip_memory_body_handler_apply_encoding(mbh, "deflate");
BC_ASSERT_EQUAL(belle_sip_memory_body_handler_unapply_encoding(mbh, "deflate"), 0, int, "%i");
belle_sip_object_unref(mbh);
}
static void test_truncated_compressed_body(void) {
belle_sip_memory_body_handler_t *mbh = belle_sip_memory_body_handler_new_copy_from_buffer((void *)parts_content[0], strlen(parts_content[0]), NULL, NULL);
belle_sip_memory_body_handler_apply_encoding(mbh, "deflate");
/* Truncate the body */
belle_sip_body_handler_set_size(BELLE_SIP_BODY_HANDLER(mbh), belle_sip_body_handler_get_size(BELLE_SIP_BODY_HANDLER(mbh)) - 5);
BC_ASSERT_EQUAL(belle_sip_memory_body_handler_unapply_encoding(mbh, "deflate"), -1, int, "%i");
belle_sip_object_unref(mbh);
}
test_t core_tests[] = {
TEST_NO_TAG("Object Data", test_object_data),
TEST_NO_TAG("Dictionary", test_dictionary),
TEST_NO_TAG("Presence marshal", test_presence_marshal)
TEST_NO_TAG("Presence marshal", test_presence_marshal),
TEST_NO_TAG("Compressed body", test_compressed_body),
TEST_NO_TAG("Truncated compressed body", test_truncated_compressed_body)
};
test_suite_t core_test_suite = {"Core", NULL, NULL, belle_sip_tester_before_each, belle_sip_tester_after_each,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment