aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objective-c/GRPCClient/private/NSData+GRPC.m
diff options
context:
space:
mode:
Diffstat (limited to 'src/objective-c/GRPCClient/private/NSData+GRPC.m')
-rw-r--r--src/objective-c/GRPCClient/private/NSData+GRPC.m10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/objective-c/GRPCClient/private/NSData+GRPC.m b/src/objective-c/GRPCClient/private/NSData+GRPC.m
index 1238374af3..98337799e9 100644
--- a/src/objective-c/GRPCClient/private/NSData+GRPC.m
+++ b/src/objective-c/GRPCClient/private/NSData+GRPC.m
@@ -42,7 +42,15 @@
static void MallocAndCopyByteBufferToCharArray(grpc_byte_buffer *buffer,
size_t *length, char **array) {
grpc_byte_buffer_reader reader;
- grpc_byte_buffer_reader_init(&reader, buffer);
+ if (!grpc_byte_buffer_reader_init(&reader, buffer)) {
+ // grpc_byte_buffer_reader_init can fail if the data sent by the server
+ // could not be decompressed for any reason. This is an issue with the data
+ // coming from the server and thus we want the RPC to fail with error code
+ // INTERNAL.
+ *array = NULL;
+ *length = 0;
+ return;
+ }
// The slice contains uncompressed data even if compressed data was received
// because the reader takes care of automatically decompressing it
gpr_slice slice = grpc_byte_buffer_reader_readall(&reader);