From e8714b93b9c22f1d43a4b71b7e673c812a4fd1a8 Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Thu, 13 Jul 2017 10:10:30 -0700 Subject: [PATCH 1/4] lib - Fix Bazel build --- BUILD | 1 + 1 file changed, 1 insertion(+) diff --git a/BUILD b/BUILD index fa423267879..e9b77868ae3 100644 --- a/BUILD +++ b/BUILD @@ -447,6 +447,7 @@ grpc_cc_library( "src/core/lib/channel/handshaker_registry.c", "src/core/lib/compression/compression.c", "src/core/lib/compression/message_compress.c", + "src/core/lib/compression/stream_compression.c", "src/core/lib/http/format_request.c", "src/core/lib/http/httpcli.c", "src/core/lib/http/parser.c", From b750d2b5aa4bc907d32b7691dd9aa00e35ea9a86 Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Thu, 13 Jul 2017 11:55:09 -0700 Subject: [PATCH 2/4] lib - Fix ubsan by add exception to zlib function --- tools/ubsan_suppressions.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/ubsan_suppressions.txt b/tools/ubsan_suppressions.txt index 83dcfc3d058..2dcfeea9afa 100644 --- a/tools/ubsan_suppressions.txt +++ b/tools/ubsan_suppressions.txt @@ -7,3 +7,4 @@ alignment:CRYPTO_cbc128_encrypt alignment:CRYPTO_gcm128_encrypt nonnull-attribute:google::protobuf::* alignment:google::protobuf::* +nonnull-attribute:_tr_stored_block From 1e9bdb5d1a9f9293052d8eb53500cc3b3900f2f3 Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Fri, 14 Jul 2017 10:14:02 -0700 Subject: [PATCH 3/4] lib - fix another Bazel build problem --- BUILD | 1 + 1 file changed, 1 insertion(+) diff --git a/BUILD b/BUILD index e9b77868ae3..c9cc6dbd3c0 100644 --- a/BUILD +++ b/BUILD @@ -574,6 +574,7 @@ grpc_cc_library( "src/core/lib/channel/handshaker_registry.h", "src/core/lib/compression/algorithm_metadata.h", "src/core/lib/compression/message_compress.h", + "src/core/lib/compression/stream_compression.h", "src/core/lib/http/format_request.h", "src/core/lib/http/httpcli.h", "src/core/lib/http/parser.h", From 0fd37e1951ae541d873d0f2803ebeb88d9c9f848 Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Thu, 13 Jul 2017 21:07:29 -0700 Subject: [PATCH 4/4] Transport - Fix a bug in decompression path --- .../chttp2/transport/chttp2_transport.c | 45 ++++++++++++++++--- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.c b/src/core/ext/transport/chttp2/transport/chttp2_transport.c index 00b0738b20d..1427b8f3302 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.c +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.c @@ -1671,9 +1671,8 @@ void grpc_chttp2_maybe_complete_recv_message(grpc_exec_ctx *exec_ctx, } if (s->stream_compression_recv_enabled && !s->unprocessed_incoming_frames_decompressed) { - grpc_slice_buffer decompressed_data; + GPR_ASSERT(s->decompressed_data_buffer.length == 0); bool end_of_context; - grpc_slice_buffer_init(&decompressed_data); if (!s->stream_decompression_ctx) { s->stream_decompression_ctx = grpc_stream_compression_context_create( @@ -1681,17 +1680,18 @@ void grpc_chttp2_maybe_complete_recv_message(grpc_exec_ctx *exec_ctx, } if (!grpc_stream_decompress(s->stream_decompression_ctx, &s->unprocessed_incoming_frames_buffer, - &decompressed_data, NULL, 5, + &s->decompressed_data_buffer, NULL, 5, &end_of_context)) { grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &s->frame_storage); grpc_slice_buffer_reset_and_unref_internal( exec_ctx, &s->unprocessed_incoming_frames_buffer); - s->seen_error = true; + error = + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Stream decompression error."); } else { error = grpc_deframe_unprocessed_incoming_frames( - exec_ctx, &s->data_parser, s, &decompressed_data, NULL, - s->recv_message); + exec_ctx, &s->data_parser, s, &s->decompressed_data_buffer, + NULL, s->recv_message); if (end_of_context) { grpc_stream_compression_context_destroy( s->stream_decompression_ctx); @@ -1740,7 +1740,38 @@ void grpc_chttp2_maybe_complete_recv_trailing_metadata(grpc_exec_ctx *exec_ctx, } bool pending_data = s->pending_byte_stream || s->unprocessed_incoming_frames_buffer.length > 0; - if (s->read_closed && s->frame_storage.length == 0 && + if (s->stream_compression_recv_enabled && s->read_closed && + s->frame_storage.length > 0 && + s->unprocessed_incoming_frames_buffer.length == 0 && !pending_data && + !s->seen_error && s->recv_trailing_metadata_finished != NULL) { + /* Maybe some SYNC_FLUSH data is left in frame_storage. Consume them and + * maybe decompress the next 5 bytes in the stream. */ + bool end_of_context; + if (!s->stream_decompression_ctx) { + s->stream_decompression_ctx = + grpc_stream_compression_context_create( + GRPC_STREAM_COMPRESSION_DECOMPRESS); + } + if (!grpc_stream_decompress(s->stream_decompression_ctx, + &s->frame_storage, + &s->unprocessed_incoming_frames_buffer, + NULL, 5, &end_of_context)) { + grpc_slice_buffer_reset_and_unref_internal(exec_ctx, + &s->frame_storage); + grpc_slice_buffer_reset_and_unref_internal( + exec_ctx, &s->unprocessed_incoming_frames_buffer); + s->seen_error = true; + } else { + if (s->unprocessed_incoming_frames_buffer.length > 0) { + s->unprocessed_incoming_frames_decompressed = true; + } + if (end_of_context) { + grpc_stream_compression_context_destroy(s->stream_decompression_ctx); + s->stream_decompression_ctx = NULL; + } + } + } + if (s->read_closed && s->frame_storage.length == 0 && s->unprocessed_incoming_frames_buffer.length == 0 && (!pending_data || s->seen_error) && s->recv_trailing_metadata_finished != NULL) { grpc_chttp2_incoming_metadata_buffer_publish(