Fail decompression when the gzip trailer is missing

pull/22929/head
Yash Tibrewal 5 years ago
parent 506cf26b49
commit 516c2f591a
  1. 4
      src/core/lib/compression/message_compress.cc
  2. 29
      test/core/compression/message_compress_test.cc

@ -68,6 +68,10 @@ static int zlib_body(z_stream* zs, grpc_slice_buffer* input,
goto error;
}
}
if (r != Z_STREAM_END) {
gpr_log(GPR_INFO, "zlib: Data error");
goto error;
}
GPR_ASSERT(outbuf.refcount);
outbuf.data.refcounted.length -= zs->avail_out;

@ -196,6 +196,34 @@ static void test_bad_decompression_data_crc(void) {
grpc_slice_buffer_destroy(&output);
}
static void test_bad_decompression_data_missing_trailer(void) {
grpc_slice_buffer input;
grpc_slice_buffer corrupted;
grpc_slice_buffer output;
size_t idx;
grpc_slice_buffer_init(&input);
grpc_slice_buffer_init(&corrupted);
grpc_slice_buffer_init(&output);
grpc_slice_buffer_add(&input, create_test_value(ONE_MB_A));
grpc_core::ExecCtx exec_ctx;
/* compress it */
grpc_msg_compress(GRPC_MESSAGE_COMPRESS_GZIP, &input, &corrupted);
/* corrupt the output by smashing the CRC */
GPR_ASSERT(corrupted.count > 1);
GPR_ASSERT(GRPC_SLICE_LENGTH(corrupted.slices[1]) > 8);
corrupted.slices[1].data.refcounted.length -= 8;
/* try (and fail) to decompress the corrupted compresed buffer */
GPR_ASSERT(0 == grpc_msg_decompress(GRPC_MESSAGE_COMPRESS_GZIP, &corrupted,
&output));
grpc_slice_buffer_destroy(&input);
grpc_slice_buffer_destroy(&corrupted);
grpc_slice_buffer_destroy(&output);
}
static void test_bad_decompression_data_trailing_garbage(void) {
grpc_slice_buffer input;
grpc_slice_buffer output;
@ -315,6 +343,7 @@ int main(int argc, char** argv) {
test_tiny_data_compress();
test_bad_decompression_data_crc();
test_bad_decompression_data_missing_trailer();
test_bad_decompression_data_stream();
test_bad_decompression_data_trailing_garbage();
test_bad_compression_algorithm();

Loading…
Cancel
Save