From 6a2cb9b2f83577b81ca69e23069790b694017973 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Fri, 7 Feb 2020 10:13:17 -0800 Subject: [PATCH] Squashed 'third_party/upb/' changes from 4c6dcc3c6b..ca84145476 ca84145476 [decoder] fix for buf=NULL, size=0 case. (#246) git-subtree-dir: third_party/upb git-subtree-split: ca84145476ddd722c6d67d7cf985d1d0aefcd893 --- tests/test_generated_code.c | 12 ++++++++++++ upb/decode.c | 3 +++ 2 files changed, 15 insertions(+) diff --git a/tests/test_generated_code.c b/tests/test_generated_code.c index ef8575cf9dc..7fd958104e2 100644 --- a/tests/test_generated_code.c +++ b/tests/test_generated_code.c @@ -340,11 +340,23 @@ void test_repeated() { upb_arena_free(arena); } +void test_null_decode_buf() { + upb_arena *arena = upb_arena_new(); + protobuf_test_messages_proto3_TestAllTypesProto3 *msg = + protobuf_test_messages_proto3_TestAllTypesProto3_parse(NULL, 0, arena); + size_t size; + + ASSERT(msg); + protobuf_test_messages_proto3_TestAllTypesProto3_serialize(msg, arena, &size); + ASSERT(size == 0); +} + int run_tests(int argc, char *argv[]) { test_scalars(); test_string_map(); test_string_double_map(); test_int32_map(); test_repeated(); + test_null_decode_buf(); return 0; } diff --git a/upb/decode.c b/upb/decode.c index ce5552af40e..8a7f64d1453 100644 --- a/upb/decode.c +++ b/upb/decode.c @@ -622,6 +622,9 @@ bool upb_decode(const char *buf, size_t size, void *msg, const upb_msglayout *l, state.depth = 64; state.end_group = 0; + /* Early exit required for buf==NULL case. */ + if (size == 0) return true; + CHK(upb_decode_message(buf, l, msg, &state)); return state.end_group == 0; }