[decoder] fix for buf=NULL, size=0 case. (#246)

pull/13171/head
Joshua Haberman 5 years ago committed by GitHub
parent 4c6dcc3c6b
commit ca84145476
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      tests/test_generated_code.c
  2. 3
      upb/decode.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;
}

@ -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;
}

Loading…
Cancel
Save